Skip to content

Commit

Permalink
PHP 8.2: explicitly declare properties (#705)
Browse files Browse the repository at this point in the history
* Locator: explicitly declare all properties

Dynamic (non-explicitly declared) property usage is expected to be deprecated as of PHP 8.2 and will become a fatal error in PHP 9.0.

There are a number of ways to mitigate this:
* If it's an accidental typo for a declared property: fix the typo.
* For known properties: declare them on the class.
* For unknown properties: add the magic `__get()`, `__set()` et al methods to the class or let the class extend `stdClass` which has highly optimized versions of these magic methods build in.
* For unknown _use of_ dynamic properties, the `#[AllowDynamicProperties]` attribute can be added to the class. The attribute will automatically be inherited by child classes.

In this case, the `$dom` property is referenced multiple times throughout this class, so falls in the "known property" category.

Refs:
* https://wiki.php.net/rfc/deprecate_dynamic_properties

* Sanitize: explicitly declare all properties

Dynamic (non-explicitly declared) property usage is expected to be deprecated as of PHP 8.2 and will become a fatal error in PHP 9.0.

There are a number of ways to mitigate this:
* If it's an accidental typo for a declared property: fix the typo.
* For known properties: declare them on the class.
* For unknown properties: add the magic `__get()`, `__set()` et al methods to the class or let the class extend `stdClass` which has highly optimized versions of these magic methods build in.
* For unknown _use of_ dynamic properties, the `#[AllowDynamicProperties]` attribute can be added to the class. The attribute will automatically be inherited by child classes.

In this case, the `$registry` property is referenced multiple times throughout this class, so falls in the "known property" category.

Refs:
* https://wiki.php.net/rfc/deprecate_dynamic_properties

* Autoloader: explicitly declare all properties

Dynamic (non-explicitly declared) property usage is expected to be deprecated as of PHP 8.2 and will become a fatal error in PHP 9.0.

There are a number of ways to mitigate this:
* If it's an accidental typo for a declared property: fix the typo.
* For known properties: declare them on the class.
* For unknown properties: add the magic `__get()`, `__set()` et al methods to the class or let the class extend `stdClass` which has highly optimized versions of these magic methods build in.
* For unknown _use of_ dynamic properties, the `#[AllowDynamicProperties]` attribute can be added to the class. The attribute will automatically be inherited by child classes.

In this case, the `$path` property is referenced a couple of times throughout this class, so falls in the "known property" category.

Refs:
* https://wiki.php.net/rfc/deprecate_dynamic_properties

* SimplePie_Cache_Redis: fix bug for using undefined property

The `$ttl` property is not declared, not set on this cache, nor its parent, which means that it would always be passed as `null`.

As the call to the `Redis::expire()` method is within a `if ($this->options['expire'])` condition and a similar call to the `Redis::expire()` method in the `SimplePie_Cache_Redis::save()` method, also uses `$this->options['expire']` for the "ttl" value, changing the passed parameter to `$this->options['expire']` seems the correct fix.

Co-authored-by: jrfnl <[email protected]>
  • Loading branch information
jrfnl and jrfnl committed Dec 19, 2021
1 parent 417a166 commit 76be63e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
*/
class SimplePie_Autoloader
{
protected $path;

/**
* Constructor
*/
Expand Down
2 changes: 1 addition & 1 deletion library/SimplePie/Cache/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function touch() {
if ($data !== false) {
$return = $this->cache->set($this->name, $data);
if ($this->options['expire']) {
return $this->cache->expire($this->name, $this->ttl);
return $this->cache->expire($this->name, $this->options['expire']);
}
return $return;
}
Expand Down
1 change: 1 addition & 0 deletions library/SimplePie/Locator.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class SimplePie_Locator
var $max_checked_feeds = 10;
var $force_fsockopen = false;
var $curl_options = array();
var $dom;
protected $registry;

public function __construct(SimplePie_File $file, $timeout = 10, $useragent = null, $max_checked_feeds = 10, $force_fsockopen = false, $curl_options = array())
Expand Down
1 change: 1 addition & 0 deletions library/SimplePie/Sanitize.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class SimplePie_Sanitize
var $useragent = '';
var $force_fsockopen = false;
var $replace_url_attributes = null;
var $registry;

/**
* List of domains for which to force HTTPS.
Expand Down

0 comments on commit 76be63e

Please sign in to comment.