Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Look ma, it’s PHP

Look ma, it’s PHP

Things you can do, and you probably didn’t know

In these slides I'll show some features that arrived to PHP since 7.0 version to the actual 8.0

Avatar for Francisco Santamaria

Francisco Santamaria

February 26, 2021
Tweet

More Decks by Francisco Santamaria

Other Decks in Programming

Transcript

  1. List of features since PHP 7.0 (2015) I • Already

    there: (built-in web server, closures, traits, generators, finally, short array syntax, function array dereferencing... ) • Nullable types • Void return type • Iterable pseudo-type • Class constant visibility • Multi catch exception handling • object as typehint • Parameter type widening • Trailing commas in list syntax • Libsodium as part of PHP core • Argon2 as hash algorithm • Performance • New Exception hierarchy • Null coalescing operator • Return and scalar type declarations • Anonymous classes • Space ship operator • Uniform variable syntax • Group use declarations
  2. List of features since PHP 7.0 (2015) II • Flexible

    heredoc & nowdoc syntax • Named arguments • Attributes • Constructor property promotion • Union Types • Match expression • Nullsafe operator • Sanner string to number comparis. • JIT • Trailing comma in parameter lists • Non capturing catches • New string functions • Typed properties • Arrow functions • Numeric Literal separator • Opcache preloading • Covariance/Contravariance • Unpacking inside arrays
  3. Topics • Types • Exceptions • New Operators • New

    functions • Security • Performance • New language syntax • Consistency
  4. Security • Libsodium is a modern cryptography library that offers

    authenticated encryption, high-speed elliptic curve cryptography,... • Provides argon2i(d) implementations for password_hash
  5. Opcache preloading • Include files or call opcache_compile_file() function •

    Need to restart the web server (FPM), reloading won’t work! • Most noticeable gains with requests with short very runtimes, such as microservices.
  6. JIT JIT (Just In Time) is a technique that will

    compile parts of the code at runtime, so that the compiled version can be used instead. “ ”
  7. JIT

  8. JIT

  9. JIT • Significantly better performance for numerical code. • Slightly

    better performance for "typical" PHP web application code. • The potential to move more code from C to PHP, because PHP will now be sufficiently fast. • It opens the door for PHP to be used as a very performant language outside of the web.
  10. Uniform variable syntax • Try to make the language more

    uniform. • Normally variable accesses are interpreted from left to right. • Solves dereferencing problems. • New meaning. • Be careful, could be backward incompatible.
  11. Links • https://wiki.php.net/rfc • https://stitcher.io/blog/new-in-php-74 • https://symfony.com/blog/new-in-symfony-4-4-preloading-symfony-applications-in-php-7-4 • https://blog.frankdejonge.nl/array-destructuring-in-php/ •

    https://stitcher.io/blog/attributes-in-php-8 • https://www.phoronix.com/scan.php?page=article&item=php8-jit-june&num=1 • https://paragonie.com/book/pecl-libsodium • https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science) • https://medium.com/swift-india/solid-principles-part-3-liskov-substitution-principle-723e025d0589 • https://www.slideshare.net/nikita_ppv/justintime-compiler-in-php-8 • https://mnapoli.fr/anonymous-classes-in-tests/ All images have copyright from Marvel Studios