note 28247 added to function.array-map
| From: | stephen at mu dot com dot au | Date: | Tue, 07 Jan 2003 04:02:12 +0000 |
| Subject: | note 28247 added to function.array-map | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-41776@lists.php.net to get a copy of this message | ||
A note when doing something allong the lines of:
class foo {
var $var;
function bar() {
array_map(array($this, "baz"), array(1,2,3));
}
function baz($arg) {
$this->var = $this->var + $arg;
}
}
This will *not* work as expected. You need to pass $this by reference as with:
array_map(array(&$this, "baz"), array(1,2,3));
or you'll be making a copy of the object each time, changing a value, then throwing the result
away.
--
http://www.php.net/manual/en/function.array-map.php
http://master.php.net/manage/user-notes.php?action=edit+28247
http://master.php.net/manage/user-notes.php?action=delete+28247
http://master.php.net/manage/user-notes.php?action=reject+28247