Doc #80482 [Opn]: Undocumented behavior of array_walk with objects
| From: | requinix@php.net | Date: | Thu, 03 Dec 2020 19:26:28 +0000 |
| Subject: | Doc #80482 [Opn]: Undocumented behavior of array_walk with objects | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-18193@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80482&edit=1
ID: 80482
Updated by: requinix@php.net
Reported by: php4fan at gmail dot com
Summary: Undocumented behavior of array_walk with objects
Status: Open
Type: Documentation Problem
-Package: Documentation problem
+Package: Arrays related
Operating System: all
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
There has been no change in how array_walk behaves. This is entirely due to a change in how
ArrayObject behaves. Why should array_walk's documentation try to cover nuances of how
unrelated classes work? It's not like string functions have comments when some class's
__toString implementations change.
Previous Comments:
------------------------------------------------------------------------
[2020-12-03 17:45:11] php4fan at gmail dot com
Description:
------------
---
From manual page: https://php.net/function.array-walk
---
The documentation says that the first parameter of array_walk must be an array, but in reality it
also works when passed an object, and it iterates over the properties.
Also, when used on ArrayObject (which, again, is undocumented in itself), this function is affected
by a dramatic bc-breaking change in 7.4 that is described in the migration guide:
https://www.php.net/manual/en/migration74.incompatible.php#migration74.incompatible.spl
(there's no specific mention of array_walk but I guess it falls under "etc." and
"potentially others")
Namely, when calling array_walk() on an array object, prior to 7.4 it would iterate over the wrapped
array/object, while starting from 7.4 it iterates over the properties of the ArrayObject itself.
This should be documented in From manual page: https://php.net/function.array-walk
Test script:
---------------
.
Expected result:
----------------
.
Actual result:
--------------
.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80482&edit=1