Bug #79384 [NEW]: property_exists on Traversable

From: Date: Sun, 15 Mar 2020 12:57:06 +0000
Subject: Bug #79384 [NEW]: property_exists on Traversable
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226115@lists.php.net to get a copy of this message
From: michal dot bundyra at gmail dot com Operating system: ANY PHP version: 7.4.3 Package: *General Issues Bug Type: Bug Bug description:property_exists on Traversable Description: ------------ As of PHP 7.4 using array_key_exists on objects is deprecated. The suggestion is to use isset or property_exists instead. The behaviour or both is different - one can detect null and the other can't. Before in code we had: ``` $valueExists = array_key_exists($key, $data); ``` and it was working for any Traversable|array $data. We are trying update our code and I thought it would be: ``` $valueExists = is_array($data) && array_key_exists($key, $data) || $data instanceof Traversable && property_exists($data, $key); ``` but unfortunately it is not working as expected. Test script: --------------- Please consider the following example: ``` $ao = new ArrayObject(['a' => null]); var_dump($ao instanceof Traversable); // true var_dump(array_key_exists('a', $ao)); // true but reports deprecated notice on PHP 7.4+ var_dump(property_exists($ao, 'a')); // false -> I would expect true here, as $ao is Traversable ``` Expected result: ---------------- property_exists works on Traversable as array_key_exists worked before. Actual result: -------------- property_exists does not work on every Traversable. I've noted that it is possible to set ArrayObject::ARRAY_AS_PROPS flat on ArrayObject and this might be the solution. But honestly I am not sure if it is by design or should be fixed. -- Edit bug report at https://bugs.php.net/bug.php?id=79384&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79384&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79384&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79384&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79384&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79384&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79384&r=support Expected behavior: https://bugs.php.net/fix.php?id=79384&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79384&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79384&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79384&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79384&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79384&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79384&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79384&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79384&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79384&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79384&r=mysqlcfg

« previous php.bugs (#226115) next »