note 28247 modified in function.array-map by aidan

From: Date: Tue, 06 Jul 2004 08:29:29 +0000
Subject: note 28247 modified in function.array-map by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72718@lists.php.net to get a copy of this message
A note when doing something allong the lines of: <?php 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. --was-- 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://php.net/manual/en/function.array-map.php

« previous php.notes (#72718) next »