[wp-trac] [WordPress Trac] #52728: Widgets: Uncaught TypeError in PHP 8 when using objects for settings
WordPress Trac
noreply at wordpress.org
Sat Mar 6 13:26:18 UTC 2021
#52728: Widgets: Uncaught TypeError in PHP 8 when using objects for settings
---------------------------------------------+---------------------
Reporter: dlh | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 5.8
Component: Widgets | Version: 4.3
Severity: normal | Resolution:
Keywords: has-patch php8 needs-unit-tests | Focuses:
---------------------------------------------+---------------------
Changes (by jrf):
* keywords: has-patch php8 => has-patch php8 needs-unit-tests
Comment:
Notwithstanding the note about this in the PHP manual:
> For backward compatibility reasons, `array_key_exists()` will also
return `true` if key is a property defined within an object given as
array. This behaviour is deprecated as of PHP 7.4.0, and removed as of PHP
8.0.0.
>
> To check whether a property exists in an object, `property_exists()`
should be used.
Source: https://www.php.net/manual/en/function.array-key-exists.php
... I wonder if this isn't actually a bug/missing feature in PHP itself.
Both the `ArrayIterator` class as well as the `ArrayObject` class
implement `ArrayAccess` and implement the `offsetExists()` method.
That method [https://www.php.net/manual/en/arrayaccess.offsetexists.php is
documented] to be invoked when `isset()` or `empty()` is used, but I
wonder if it shouldn't also be invoked when `array_key_exists()` is
called.
Other than that, the patch looks good, though I'd like to see some tests
with widgets using ArrayObjects or ArrayIterators being added. These tests
should fail on PHP 8.0 without this patch and would safeguard the PHP 8.0
compatibility.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/52728#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list