[wp-trac] [WordPress Trac] #61890: Handle WP_Term known, named dynamic properties for PHP 8.2
WordPress Trac
noreply at wordpress.org
Wed Aug 21 17:59:32 UTC 2024
#61890: Handle WP_Term known, named dynamic properties for PHP 8.2
-------------------------------------+-------------------------------------
Reporter: hellofromTonya | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 6.7
Component: Taxonomy | Version:
Severity: minor | Resolution:
Keywords: php82 has-patch has- | Focuses: coding-standards, php-
unit-tests | compatibility
-------------------------------------+-------------------------------------
Comment (by hellofromTonya):
**Declaring the known, named dynamic properties**
This approach is the one recommended in #56034:
>Declare the property on the (parent) class
What will the behavior be if all of the known, named dynamic properties
are declared on the class?
See in action https://3v4l.org/SpW2N#veol.
The only change is to declare the known, named dynamic properties. Note:
For this strategy, would also want to throw a deprecation for unknown
dynamic properties.
Results as compared to the [comment:4 current behavior]:
* ✅ get, isset, set, unset of known dynamic property works.
* ✅ get, isset, set, unset of unknown dynamic property works.
* ✅ `WP_Term::$data` is initialized on get and is not included when using
`WP_Term::to_array()` or `(array) $term`.
* ✅ `WP_Term::to_array()` returns all of the declared properties and all
dynamic properties.
* ❌ Difference from the current behavior: all of the known, named
dynamic properties are also included in the resultant array, even if they
were not used or initialized.
* ✅ Same results when converting object to array via
`WP_Term::to_array()` and `(array) $term`.
* No deprecation notices are thrown.
A few observations:
1. The differences between current behavior to this approach when
converting from object to array is not a BC break IMO. Why? It's
additional information / elements, but should not break existing behavior.
Furthermore, adding new properties to existing Core classes is not
considered a BC break; else, it would limit the ability for Core's classes
to be enhanced over the years.
2. It is confusing why unused properties are returned, when previously
they were only there when needed (such as when using a tag cloud).
3. It's also confusing why these properties are in the class, which could
be a maintenance concern (will confuse contributors).
4. That said, `WP_Term::to_array()` could be modified to exclude these
unused/uninitialized properties to retain the current behavior and array
shape.
5. Doing 4 though means type casting would result in a different array
shape. But this doesn't concern me either, as `WP_Term::to_array()` is the
preferred way to convert to an array. A dev note can provide guidance for
extenders to make changes.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61890#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list