note 51707 added to function.array-walk
| From: | PHPNovice at osu1 dot php dot net | Date: | Fri, 08 Apr 2005 05:35:35 +0000 |
| Subject: | note 51707 added to function.array-walk | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-87687@lists.php.net to get a copy of this message | ||
While Hayley's comments about pass-by-reference will work for now, this is a deprecated
feature. I've been working with array_walk in a class and inside the callback I want to alter a
member field of the object. What I've discovered is that the $this object present during the
invokation of the callback is a copy of the original object. This of course means that your
modifications will be lost when you return from the array_walk call. The only solutions I've
come up with for this is to use the runtime pass-by-reference mechanism to provide a reference to
the field I want to modify and get the deprecation warning or break the encapsulation of my class
by using a global. (YUCK!) Can a PHP guru show me what I've missed (if anything) regarding this
issue?
----
Manual Page -- http://www.php.net/manual/en/function.array-walk.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51707
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51707&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51707&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51707&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51707&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51707&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51707&report=yes
Search -- http://master.php.net/manage/user-notes.php