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

PHP Dynamic Properties

PHP Dynamic Properties

Introduction for the mob programming session of December 17, 2021, with as the topic: scoping out the impact of the PHP 8.2 deprecation of dynamic properties.

Slides set forth the problem outline and review tasks.

Missed it ? The recording is (will be) available as video on demand at https://www.youtube.com/c/hellofromtonya/videos

----

Links:
* PHP 8.2 RFC
* Results of initial test run of WP Core against PHP 8.2
* Exakat plugin scan results
* Spreadsheet to record findings

Juliette Reinders Folmer

December 17, 2021
Tweet

More Decks by Juliette Reinders Folmer

Other Decks in Programming

Transcript

  1. PHP Dynamic Properties Scoping the impact of the PHP 8.2

    deprecation Juliette Reinders Folmer Tweet about it: @jrf_nl
  2. Why are we talking about this ? ▪ Dynamic properties

    will be deprecated in PHP 8.2 (most likely) ▪ … and will become Error Exceptions (fatal errors) in PHP 9.0 Full details: https://wiki.php.net/rfc/deprecate_ dynamic_properties
  3. Why are we talking about this NOW ? ▪ Scope

    of problem is unknown ▪ Plugins often not actively maintained ▪ If not mitigated in time, could cause absolute havoc once PHP 9.0 comes round
  4. What Are Dynamic Properties ? class Foo { public $id;

    public function __construct( $id, $field_name ) { $this->id = $id; $this->field_name = $field_name; } }
  5. What Are Dynamic Properties ? class Foo_Parent { protected $field_name;

    } class Foo extends Foo_Parent { public $id; public function __construct( $id, $field_name ) { $this->id = $id; $this->field_name = $field_name; } } ✔
  6. What Are Dynamic Properties ? class Foo { private $fields

    = []; public function __construct($field_name ) { $this->field_name = $field_name; } public function __set( $name, $value ) { $this->fields[ $name ] = $value; } public function __get( $name ) { ... } public function __isset( $name ) { ... } public function __unset( $name ) { ... } } ✔
  7. What Are Dynamic Properties ? class Foo { public $id;

    public function __construct( $id, $field_name ) { $this->Id = $id; } } Typo
  8. Mitigation Options Typo Fix it Known dynamic properties Declare the

    properties on the (parent) class Unknown dynamic properties Add magic methods to the (parent) class Unknown use of dynamic properties Add #[AllowDynamicProperties] attribute to (parent) class
  9. Action Plan ❑Get insight into the scope of the problem

    ❑ Evaluate results of initial test run WP Core on PHP 8.2 ❑ Validate Exakat analysis results for a sampling of plugins ❑Give feedback to PHP Core ❑Future livestream: Discuss proposal on how to handle this in WP Core and warn plugin authors and users in time
  10. Property Assignment Is there a property declared with a very

    similar name? Are the magic methods available? … in a potential parent class? Is the property declared in the class? … in a potential parent class? Not a Problematic Dynamic Property (false positive) Typo Problematic Dynamic Property Yes No No No No No Yes Yes
  11. Relevant links ▪ WP Core test run results https://github.com/jrfnl/wordpress-develop-official/actions ▪

    Exakat plugin scan results https://is.gd/wpplugin_dynprop_review_input ▪ Spreadsheet to record findings https://is.gd/wpplugin_dynprop_review ▪ PHP 8.2 dynamic properties RFC https://wiki.php.net/rfc/deprecate_dynamic_properties