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

391d70e6cfd94b56b666f5074479202a?s=128

Francisco Santamaria

February 26, 2021
Tweet

Transcript

  1. Look ma, it’s PHP Things you can do, and you

    probably didn’t know
  2. Old times of PHP

  3. 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
  4. 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
  5. Topics • Types • Exceptions • New Operators • New

    functions • Security • Performance • New language syntax • Consistency
  6. Types

  7. Scalar type hints • array • Class/Interface • callable

  8. Scalar type hints

  9. Scalar type hints • int • float • bool •

    string
  10. Scalar type hints

  11. Scalar type hints

  12. Return type declarations

  13. Void return type cannot be used as a parameter type

    • •
  14. Nullable types

  15. Typed properties

  16. Typed properties

  17. Union types

  18. Iterable pseudo-type

  19. Iterable pseudo-type II

  20. Iterable pseudo-type III

  21. object as typehint

  22. Exceptions

  23. Fatal errors & warnings

  24. Last chance...

  25. New Exception hierarchy

  26. Some Error exceptions

  27. Throwables

  28. Catching Multiple Exception Types

  29. Non capturing catches

  30. New Operators

  31. Null coalesce operator

  32. Null coalesce operator II

  33. Spaceship operator

  34. Spaceship operator

  35. Null safe operator

  36. Null safe operator

  37. New functions

  38. New str_* functions

  39. Security

  40. Security • Libsodium is a modern cryptography library that offers

    authenticated encryption, high-speed elliptic curve cryptography,... • Provides argon2i(d) implementations for password_hash
  41. Performance

  42. Performance comparison (synthetic)

  43. Opcache preloading

  44. 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.
  45. 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. “ ”
  46. JIT

  47. JIT

  48. 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.
  49. New language syntax

  50. Arrow functions

  51. Named arguments

  52. Named arguments II

  53. Attributes

  54. Attributes II

  55. Constructor property promotion

  56. match expression

  57. match expression II

  58. ::class on objets

  59. Group use declarations

  60. Trailing commas

  61. Numeric Literal separator

  62. Unpacking inside arrays, (spread op.)

  63. Flexible heredoc and nowdoc syntax

  64. Array destructuring

  65. Not ES6 in Westview...

  66. Array destructuring

  67. Anonymous classes

  68. Class constant visibility

  69. More consistency

  70. Covariance/Contravariance

  71. Sanner string to number comparisons

  72. Deprecate left-associative ternary operat.

  73. 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.
  74. Uniform variable syntax II

  75. And much more... https://www.php.net/releases/

  76. None
  77. Thanks

  78. 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