Slide 1

Slide 1 text

PHP Dynamic Properties Scoping the impact of the PHP 8.2 deprecation Juliette Reinders Folmer Tweet about it: @jrf_nl

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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; } } ✔

Slide 6

Slide 6 text

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 ) { ... } } ✔

Slide 7

Slide 7 text

What Are Dynamic Properties ? class Foo { public $id; public function __construct( $id, $field_name ) { $this->Id = $id; } } Typo

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

Thanks! Any questions ? @jrf_nl @jrfnl