php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80482 Undocumented behavior of array_walk with objects
Submitted: 2020-12-03 17:45 UTC Modified: 2020-12-04 00:37 UTC
From: php4fan at gmail dot com Assigned:
Status: Closed Package: Arrays related
PHP Version: Irrelevant OS: all
Private report: No CVE-ID: None
 [2020-12-03 17:45 UTC] 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:
--------------
.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-12-03 19:26 UTC] requinix@php.net
-Package: Documentation problem +Package: Arrays related
 [2020-12-03 19:26 UTC] 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 19:44 UTC] 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-04 00:37 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2020-12-04 17:20 UTC] 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-04 17:22 UTC] phpdocbot@php.net
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
 [2020-12-04 17:22 UTC] phpdocbot@php.net
-Status: Verified +Status: Closed
 [2020-12-05 11:43 UTC] mumumu@php.net
Automatic comment from SVN on behalf of mumumu
Revision: http://svn.php.net/viewvc/?view=revision&revision=351897
Log: Fix #80482: Undocumented behavior of array_walk with objects
 [2020-12-05 11:45 UTC] phpdocbot@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=eb86749c8a9281be2ccf544ceec9deb277ab99e9
Log: Fix #80482: Undocumented behavior of array_walk with objects
 [2020-12-30 11:58 UTC] nikic@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=1f59ffe3107f2032a2b30e60d4920c3d80abae70
Log: Fix #80482: Undocumented behavior of array_walk with objects
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 06:01:30 2024 UTC