Req #80799 [NEW]: Wrong behavior for function array_column
| From: | saribekyantaron at gmail dot com | Date: | Thu, 25 Feb 2021 12:17:42 +0000 |
| Subject: | Req #80799 [NEW]: Wrong behavior for function array_column | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-232387@lists.php.net to get a copy of this message | ||
From: saribekyantaron at gmail dot com
Operating system: Any
PHP version: Next Minor Version
Package: Class/Object related
Bug Type: Feature/Change Request
Bug description:Wrong behavior for function array_column
Description:
------------
---
From manual page: https://php.net/function.array-column
---
The first parameter describes:
A multi-dimensional array or an array of objects from which to pull a
column of values from. If an array of objects is provided, then public
properties can be directly pulled. In order for protected or private
properties to be pulled, the class must implement both the __get() and
__isset() magic methods.
But I think if object's class implements interface \ArrayAccess, no need
to define magic methods (set, get, isset) for allowing them to be used
in array-management functions: like array_columns. I mean that Array***
interfaces can be enough (I will prefer required) to use objects or
object arrays in array_*** functions.
Test script:
---------------
class SimpleArrayLikeClass implements \ArrayAccess
{
public function offsetExists($name)
{
return array_key_exists($name, $this->attributes());
}
public function offsetGet($name)
{
return $this->attributes()[$name] ?? null;
}
// if object need to be used as array this 2 methods need to be used
instead of __isset() and __get()
}
Expected result:
----------------
In future versions became deprecated to use objects as array, if they
not implemented Array*** interfaces, instead of magic methods
--
Edit bug report at https://bugs.php.net/bug.php?id=80799&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80799&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80799&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80799&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80799&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80799&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80799&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80799&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80799&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80799&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80799&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80799&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80799&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80799&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80799&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80799&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80799&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80799&r=mysqlcfg