ID: 46409 Updated by: [EMAIL PROTECTED] Reported By: phpbugs at sevenlight dot com -Status: Assigned +Status: Closed Bug Type: Scripting Engine problem Operating System: * PHP Version: 5.3CVS-2008-11-11 Assigned To: dmitry New Comment:
This bug has been fixed in CVS. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2008-10-28 20:17:51] phpbugs at sevenlight dot com Description: ------------ When using a custom class as a callback object, the array_map (and possibly other methods) call the method outside of the object's context. I was using this as the __invoke() method to test: if (!isset($this)) { die('Outside of object context.'); } else { return $this->val; } This may be the best way to setup the PHP unit test script. Again I did not test this on other callback functions, but it very easily could be happening on those as well. Reproduce code: --------------- <?php class Callback { protected $val = 'hello, world'; public function __invoke() { return $this->val; } } $cb = new Callback(); // straight callback if ($cb() != 'hello, world') { die('error'); } // array_map $a = array(1, 2, 3); $b = array_map($cb, $a); print_r($b); ?> Expected result: ---------------- Array ( [0] => hello, world [1] => hello, world [2] => hello, world ) Actual result: -------------- PHP Fatal error: Using $this when not in object context in /srv/www/test/closure.php on line 8 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=46409&edit=1
