webserver • New array syntax and dereferencing • And more! • Removed some nonsense • This talk covers the best bits* * an entirely subjective selection
element from it function getList() { return ['Grumpy', 'Sleepy', 'Bashful', 'Doc']; } // grab first item from list $item = getList()[0]; echo $item; // Grumpy;
{ return "nothing changed"; } } class Princess { use Audit; // General princess class description: // soldering, tree climbing, the usual } $daisy = new Princess(); echo $daisy->getAuditTrail();
• There are rules about resolving naming clashes • Traits can include properties • Traits can include abstract methods • Traits can themselves make use of other traits
if (file_exists(__DIR__ . '/' . $_SERVER['REQUEST_URI'])) { return false; // serve the requested resource as-is } else { include_once 'index.php'; } routing.php php -S localhost:8080 routing.php The webserver runs routing.php before entering the requested script. This example serves any existing resource, or routes to index.php
} $ping = function() { echo "ping!"; }; $pong = "pong"; echo sparkles($ping); // ping!fairy dust echo sparkles($pong); Catchable fatal error: Argument 1 passed to sparkles() must be callable, string given, called in /home/lorna/.../callable.php on line 16 and defined in /home/lorna/.../callable.php on line 10
PHP provides "magic methods" for us to hook into (this isn’t new): • __sleep() to specify which fields should be serialized • __wakeup() to perform any operations needed to complete an object when it is unserialized This gives us the same feature for when we JSON something
mixed jsonSerialize () } Objects implementing the JsonSerializable interface can control how they are represented in JSON when they are passed to json_encode()