Bug #54367 [Asn->Csd]: Use of closure causes problem in ArrayAccess

From: Date: Wed, 20 Apr 2011 13:00:11 +0000
Subject: Bug #54367 [Asn->Csd]: Use of closure causes problem in ArrayAccess
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-160302@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=54367&edit=1 ID: 54367 Updated by: dmitry@php.net Reported by: jpauli@php.net Summary: Use of closure causes problem in ArrayAccess -Status: Assigned +Status: Closed Type: Bug Package: Scripting Engine problem Operating System: *nix PHP Version: 5.3.6 Assigned To: dmitry Block user comment: N Private report: N New Comment: This bug has been fixed in SVN. 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: ------------------------------------------------------------------------ [2011-04-20 14:59:21] dmitry@php.net Automatic comment from SVN on behalf of dmitry Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=310389 Log: Fixed bug #54367 (Use of closure causes problem in ArrayAccess). ------------------------------------------------------------------------ [2011-03-25 09:55:25] jpauli@php.net Felipe: strange, I got no crash with your code (5.3.6,Linux, self-compiled) ------------------------------------------------------------------------ [2011-03-24 22:49:49] felipe@php.net I can reproduce a crash with: <?php class MyObjet implements ArrayAccess { public function __construct() { } public function offsetSet($offset, $value) { } public function offsetExists($offset) { } public function offsetUnset($offset) { } public function offsetGet ($offset) { return function () { }; } } $a = new MyObjet(); echo $a['p']('foo'); ?> Breakpoint 1, 0x085368b3 in ZEND_SEND_VAL_SPEC_CONST_HANDLER (execute_data=0x8ade614, tsrm_ls=0x89022a0) at /home/felipe/dev/php5/Zend/zend_vm_execute.h:1719 1719 && ARG_MUST_BE_SENT_BY_REF(EX(fbc), opline->op2.u.opline_num)) { (gdb) p execute_data->fbc->common $7 = {type = 90 'Z', function_name = 0x5a5a5a5a <Address 0x5a5a5a5a out of bounds>, scope = 0x5a5a5a5a, fn_flags = 1515870810, prototype = 0x5a5a5a5a, num_args = 1515870810, required_num_args = 1515870810, arg_info = 0x5a5a5a5a, pass_rest_by_reference = 90 'Z', return_reference = 90 'Z'} ------------------------------------------------------------------------ [2011-03-24 13:52:23] jpauli@php.net Description: ------------ Closures cant use variables from external context when the context is in ArrayAccess method Test script: --------------- <?php class MyObjet implements ArrayAccess { // All the stuff for ArrayAccess public function offsetGet ($offset) { return function ($var) use ($offset) { // here is the problem return sprintf('<%s>%s</%$1s>', $offset, $var); }; } } $a = new MyObjet(); echo $a['p']('foo'); Expected result: ---------------- <p>foo</p> Actual result: -------------- PHP Notice: Undefined variable: offset in {file.php} on line 11 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=54367&edit=1

« previous php.bugs (#160302) next »