Skip to main content

Posts

Showing posts from September, 2012

PHP_EOL: Most Worthless Constant?

PHP_EOL may very well be the most worthless general-purpose constant in modern PHP. It's supposed to be helpful for cross-platform developing, for example you could write a PHP-powered shell script that says: <?php echo "Operation Successful!" . PHP_EOL; and then expect the proper newline to terminate the output string based on the platform PHP is running on. That's all well and good, but the following is functionally equivalent: <?php echo "Operation Successful!\n"; Try it out and you'll see. In console output on Windows, Linux, and Mac they all are displayed with the expected newline terminating the output string. I don't see it being useful for writing data or log output to a file either. If you're writing and reading on the same platform then newline discrepancies won't be an issue, and if you're writing on one platform and reading on another then you'll want to standardize on a newline anyway. Has PHP_EOL ...