humanmade / humanmade/extendable-aggregator
Static variables in inherited method changes in PHP 8.1 affect the plugin admin features
- Dominant language
- PHP
- Stars
- 7
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
[Static variables in inherited method changes in PHP 8.1](https://wiki.php.net/rfc/static_variable_inheritance) affect the plugin admin features.
Before PHP 8.1, when a method containing static variables is inherited, the inherited method uses an independent set of static variables. After PHP 8.1, one set of static variables per method is maintained, which means it is shared across classes. You can find more details [here](https://www.exakat.io/en/fix-inherited-static-variables-in-php-8-1/). Unfortunately, this is causing a problem with the `extendable-aggregator` plugin.
See how the output change between different PHP versions [here](https://3v4l.org/s68Qn).
It can be fixed by changing the get_instance method [here](https://github.com/humanmade/extendable-aggregator/blob/b837f569ccb734aaadb7c6b0acd82b475e1c83d2/inc/admin/class-base.php#L54) like below or with better alternative.
```
/**
* Get the singleton class instance
*
* @return static Base
*/
public static function get_instance() {
static $instance = [];
if ( empty( $instance[ static::class ] ) ) {
$instance[ static::class ] = new static();
}
return $instance[ static::class ];
}
```
See it in action [here](https://3v4l.org/ZEflB) with a similar example as above.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.