PHP 8.2: explicitly declare properties#705
Merged
mblaney merged 4 commits intosimplepie:masterfrom Dec 19, 2021
Merged
Conversation
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
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
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
Member
|
I think |
Contributor
Author
Good call, makes perfect sense. I've added an extra commit to address this. |
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.
cbee5e5 to
ff2f3c8
Compare
jtojnar
approved these changes
Dec 19, 2021
Member
jtojnar
left a comment
There was a problem hiding this comment.
I am surprised var is still allowed in PHP 8, GitHub syntax highlighter does not seem to know it 🤣
Member
|
thanks @jrfnl |
Contributor
Author
It is, though it is highly recommended to use visibility modifiers instead. Happy to change that throughout the codebase, but that was out of scope for this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
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:
__get(),__set()et al methods to the class or let the class extendstdClasswhich has highly optimized versions of these magic methods build in.#[AllowDynamicProperties]attribute can be added to the class. The attribute will automatically be inherited by child classes.Refs:
Commits
Locator: explicitly declare all properties
In this case, the
$domproperty is referenced multiple times throughout this class, so falls in the "known property" category.Sanitize: explicitly declare all properties
In this case, the
$registryproperty is referenced multiple times throughout this class, so falls in the "known property" category.Autoloader: explicitly declare all properties
In this case, the
$pathproperty is referenced a couple of times throughout this class, so falls in the "known property" category.🆕 SimplePie_Cache_Redis: fix bug for using undefined property
The
$ttlproperty is not declared, not set on this cache, nor its parent, which means that it would always be passed asnull.As the call to the
Redis::expire()method is within aif ($this->options['expire'])condition and a similar call to theRedis::expire()method in theSimplePie_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.QA
The existing unit tests already cover these changes.
A scan with @exakat reveals one more issue, but I'm not sure how to fix that one:TheSimplePie_Cache_Redis::touch()method refers to (uses) a$ttlproperty, but this property is not declared on the class, nor set anywhere, so it is unclear what the value of the property should be when explicitly declaring it on the class.