php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79384 property_exists on ArrayObject
Submitted: 2020-03-15 12:57 UTC Modified: 2020-03-15 13:01 UTC
From: michal dot bundyra at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.4.3 OS: ANY
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: michal dot bundyra at gmail dot com
New email:
PHP Version: OS:

 

 [2020-03-15 12:57 UTC] michal dot bundyra at gmail dot com
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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-03-15 13:01 UTC] requinix@php.net
-Summary: property_exists on Traversable +Summary: property_exists on ArrayObject -Status: Open +Status: Not a bug
 [2020-03-15 13:01 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This has nothing to do with Traversable.

https://www.php.net/manual/en/migration74.incompatible.php#migration74.incompatible.spl
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 16:01:38 2025 UTC