note 51709 added to function.array-walk

From: Date: Fri, 08 Apr 2005 06:17:45 +0000
Subject: note 51709 added to function.array-walk
Groups: php.notes 
Request: Send a blank email to php-notes+get-87689@lists.php.net to get a copy of this message
Beware that "array ($this, method)" construct. If you're wanting to alter members of the "$this" object inside "method" you should construct the callback like this: $callback[] = &$this; $callback[] = method; array_walk ($input, $callback); Creating your callback using the array() method as suggested by "appletalk" results in a copy of $this being passed to method, not the original object, therefor any changes made to the object by method will be lost when array_walk() returns. While you could construct the callback with "array(&$this, method)", I believe this relies on the deprecated runtime pass-by-reference mechanism which may be removed in future releases of PHP. Better to not create a dependence on that feature now than having to track it down and fix it in the future. ---- Manual Page -- http://www.php.net/manual/en/function.array-walk.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51709 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51709&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51709&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51709&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51709&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51709&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51709&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87689) next »