Register Globals is Gone (5.4) Upgrade PHP and see many undefined (simple) variables. To fix each undefined variable: •replace $username with $_GET['username'] or $_POST['username'] in each case
Timezone Settings (5.4) PHP refuses to guess the timezone and will warn you. It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. Fix it by setting date.timezone in php.ini: date.timezone = "Europe/London"
Call Time Pass By Reference PHP Fatal error: Call-time pass-by-reference has been removed This error says "don't pass references in when the function didn't expect them, you fool"
Call Time Pass By Reference You can pass by reference. Declare function: 1 function inspire(&$person) { 2 // be inspiring 3 } Call with just $ and not & 1 inspire($current_user);
Traits To use a trait: 1 use Silex\Application; 2 class MyApplication extends Application { 3 use Application\MonologTrait; 4 5 public function myAwesomeMethod() { 6 ... 7 $this->log("Something happened"); 8 ...
MySQL Extension is Deprecated (5.5) The original mysql extension now emits E_DEPRECATED warnings. Instead, use: •PDO - excellent OO database handling •The mysqli extension, quite similar to the original mysql one
DebugInfo (5.6) Magic method __debugInfo() to change what is given to var_dump() 1 class MyBuggyClass { 2 public function __debugInfo() { 3 return $this->problemData; 4 } 5 } 6 7 ... 8 var_dump(new MyBuggyClass()); // custom output
How To Upgrade •Turn on E_DEPRECATED and watch the logs of your existing platform •Use the PHPCompatibility PHPCS standard •Lint check with new version (php -l) •Compile new PHP and run test suite •Run application with PHP's webserver •Upgrade a test/staging platform •Go for it!
Namespaced Functions (5.6) Have always been able to namespace functions Can now import them, like classes 1 include "Lib/Many/Layers/functions.php"; 2 use function \Lib\Many\Layers\deep_func; 3 4 deep_func();
JSON Shininess (5.4) JSONSerializable interface defines the data that is included when object is passed to json_encode() Also very handy additional switches to json_encode(): •JSON_PRETTY_PRINT •JSON_UNESCAPED_SLASHES •JSON_UNESCAPED_UNICODE