Doc #80482 [Ver->Csd]: Undocumented behavior of array_walk with objects
| From: | phpdocbot@php.net | Date: | Fri, 04 Dec 2020 17:22:10 +0000 |
| Subject: | Doc #80482 [Ver->Csd]: Undocumented behavior of array_walk with objects | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-18199@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: phpdocbot@php.net
Reported by: php4fan at gmail dot com
Summary: Undocumented behavior of array_walk with objects
-Status: Verified
+Status: Closed
Type: Documentation Problem
Package: Arrays related
Operating System: all
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=19af072c3eb88de9b99be2e982af8949f0b68a95
Log: Fix #80482: Undocumented behavior of array_walk with objects
Previous Comments:
------------------------------------------------------------------------
[2020-12-04 17:20:45] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=351878
Log: Fix #80482: Undocumented behavior of array_walk with objects
------------------------------------------------------------------------
[2020-12-03 19:44:53] php4fan at gmail dot com
> There has been no change in how array_walk behaves. This is entirely due to a
> change in how ArrayObject behaves
Oh, that's interesting. Maybe I could have known that if the documentation of ArrayObject
itself was decent.
This part of the report I believe is still valid:
"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."
------------------------------------------------------------------------
[2020-12-03 19:26:28] requinix@php.net
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.
------------------------------------------------------------------------
[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