PHP tags – once and for all. Yet again.

For those of us who have been using PHP since the early version 3 days and such, here is a modern day refresher for PHP tags:

If a file is pure PHP code, it is preferable to omit the PHP closing tag at the end of the file. This prevents accidental whitespace or new lines being added after the PHP closing tag, which may cause unwanted effects because PHP will start output buffering when there is no intention from the programmer to send any output at that point in the script.

And from the comment on the same page:

Since PHP 5.4 the inline echo <?= ?> short tags are always enabled regardless of the short_open_tag (php.ini) setting.

For me personally, closing PHP tags are a part of muscle memory.  I’ll have to unlearn that, I guess.  And in regards to the inline echo tags, I was under the impression that they are being phased out together with the other short tags (<? … ?>).  Apparently, I was wrong.  They are here to stay.  Which explains why there are in PSR-1, PSR-2, and in CakePHP 3 (which requires PHP 5.4.16 and fully adopts PSR-2) in particular.

nightrain – PHP packager for native applications on Windows, Linux, and Mac OS

PHP Nightrain is a packager written in Python for the PHP Programming Language. Using this tool you can convert your PHP/HTML/CSS/Javascript application to a Native Desktop Application. Currently, PHP Nightrain supports the Windows, Mac (OS X) and the Linux operating systems.  This is basically PhoneGap for desktop.

URL rewriting in built-in web server of PHP

PHP comes with a handy for development built-in web server.  However, most web projects have friendly URLs these days which are either Apache (mod_rewrite) or Nginx specific configuration.  This almost renders built-in PHP web server useless.  Unless you provide a PHP-based routing, like so:

$request_uri = __DIR__ . $_SERVER["REQUEST_URI"];
if (file_exists($request_uri)) {
  return false;
} else {
  include __DIR__ . ‘/index.php';
}

Start the PHP web server with the following command then (routing.php being a file with the above content):

$ cd my-project && php -S localhost:8000 routing.php

Thanks to this blog post and comments.  Now you can completely skip having Apache and Nginx on developer machines and all that shenanigan with configuring virtual hosts, modules, and such.

phpdotenv – Loads environment variables from .env file to getenv(), $_ENV and $_SERVER automagically

phpdotenv – Loads environment variables from .env file to getenv(), $_ENV and $_SERVER automagically