PHP is constantly evolving and getting better and faster. Come learn about the latest features in the language from the past few years and what's coming up very soon in version 7.4.
“ I did not develop the PHP we know today. Dozens, if not hundreds of people, developed PHP. I was simply the first developer. — R A S M U S L E R D O R F — 3
Thank You Nikita Popov nikic is an exceptional programmer, and has been responsible for so many of PHP’s recent improvements, both in performance & syntax. 4
Contravariance in Parameters class Mapper { public function map(Iterator $i) {...} } class ArrayMapper extends Mapper { public function map(iterable $iter) { return parent::map(iterator_for($iter)); } } 13
Preloading ◦ Part of Opcache ◦ Write a PHP script to preload files ◦ Executed once on server startup ◦ All preloaded files are available in memory for ALL requests ◦ Changes made to the source file won't have any effect, until the server is restarted 15
Preloading # In your INI opcache.preload=/path/to/preload.php # In your preload.php $files = /* files to preload */; foreach ($files as $file) { opcache_compile_file($file); } 16
Unpacking Arrays $data = ['b', 'c', 'd']; $more = ['a', …$data, 'e', 'f']; # Works with Iterators too $other = ['a', …$iterator, 'e']; # But not with Associative Arrays 18
Goodbye iterator_to_array(); # These two lines do the same thing $array = iterator_to_array($iter); $array = […$iter]; # Again, it doesn’t work with # associative arrays. 19
New Serialization ◦ Old way: ◦ __sleep() and __wakeup() methods ◦ Serializable interface ◦ New __serialize() and __unserialize() ◦ Addresses issues with previous implementations ◦ Serializable interface will be deprecated 32
New Custom Serialization Methods class Foo { private $bar; public function __serialize(): array { return ['bar' => $this->bar]; } public function __unserialize(array $data) { $this->bar = $data['bar']; } } 33
Credits Special thanks to all the people who made and released these awesome resources for free: ◦ Presentation template by SlidesCarnival ◦ Photographs by Unsplash 35