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

Tackling the ElePHPant in the Room

Tackling the ElePHPant in the Room

Presented on June 22nd 2023 at the Brussels PHP meetup, Brussels, Belgium.
https://www.meetup.com/brusselsphp/events/293335070/
---------------------------------------------------------------
Preparing for compatibility with a new PHP version... for some of us it's something to spend some time on every few years or so, for others, like those of us managing open source projects, it's a yearly chore which can take months of work.
PHPCompatibility is one of the tools which can help you find PHP cross-version incompatibilities.
In this talk, Juliette will give an introduction on how PHPCompatibility can help you, but more importantly, will take you behind the scenes and give you some insight into the enormous impact the plethora of syntax enhancements in PHP itself has on tooling like PHPCompatibility.
Fasten your seatbelt and prepare for a wild ride!

More Decks by Juliette Reinders Folmer

Other Decks in Programming

Transcript

  1. Tackling the ElePHPant in the Room Juliette Reinders Folmer Tweet

    about it: @jrf_nl #BrusselsPHP Rolf Dobberstein
  2. PHPCompatibility ▪ Deprecated: warning ▪ Removed: error ▪ New: error

    Modular error codes for optimal configurability
  3. TestVersion ? Fixed testVersion 7.3 Range testVersion 7.3-8.1 Up to

    testVersion -8.1 Minimum and up testVersion 7.3- Barbary Dougherty
  4. PHP 8.2 Partially Supported Callables Deprecation "self::method" "parent::method" "static::method" ["self",

    "method"] ["parent", "method"] ["static", "method"] ["Foo", "Bar::method"] [new Foo, "Bar::method"] call_user_func($callback, $param); $callback()
  5. Fixed of not ? class Foo { public function bar()

    { // Do something conditionally if a child class // has implemented a certain method. if (is_callable('static::methodName')) { call_user_func('static::methodName'); static::methodName(); } } }
  6. Limitations ▪ Context: current file only ▪ No access to

    runtime values (variables) Stefan Parnet
  7. Getting Ready: PHP_CodeSniffer Adjust existing sniffs to allow for new

    PHP version Backfill/Polyfill new syntaxes Ensure dependencies are compatible Make own code compatible
  8. Getting Ready: PHPCompatibility Detect new incompatibilities Adjust existing sniffs to

    allow for new PHP version Ensure dependencies are compatible Make own code compatible
  9. New syntaxes/tokenizer changes PHP 5.5 5.6 7.0 7.1 7.2 7.3

    7.4 8.0 8.1 8.2 New operators 2 3 1 1 1 New constructs 4 1 6 1 1 1 9 4 2 Other relevant changes 1 1 1 4 2 2 2 5 4 3
  10. Impact of New Syntaxes [1] // Deprecated PHP 7.4, removed

    PHP 8.0. is_real($var); // False positive prevention: $this->is_real($var); MyClass::is_real($var); MyNamespace\is_real($var); // PHP 8.0+ nullsafe object operator… $obj?->is_real($var);
  11. Impact of New Syntaxes [2] class Foo { // PHP

    7.4+ Typed property. public string $propA; // PHP 7.0+ Scalar type declaration, // PHP 7.1+ nullable type. public function bar(?int $param) {} // Oops... public function __construct(public ?int $propB) {} }
  12. Impact of New Syntaxes [3] // PHP 8.1+ new hash

    algorithm. hash_init('xxh64'); // Argh...! hash_init( flags: HASH_HMAC, key: 'mysecret', algo: 'xxh64', );
  13. What's Next ? ▪ PHPCompatibility 10.0 expected soon(ish) ▪ New

    contributors (and sponsors!) welcome! Ben Kerckx