Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:16301 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 13531 invoked by uid 1010); 27 May 2005 13:18:38 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 1197 invoked from network); 27 May 2005 13:07:20 -0000 Received: from unknown (HELO zend.com) (127.0.0.1) by localhost with SMTP; 27 May 2005 13:07:20 -0000 X-Host-Fingerprint: 84.204.52.251 promo.hnet.spb.ru OpenBSD 3.0-3.4 Received: from ([84.204.52.251:21701] helo=promo.hnet.spb.ru) by pb1.pair.com (ecelerity 1.2 r(5656M)) with SMTP id 42/35-15978-68B17924 for ; Fri, 27 May 2005 09:07:19 -0400 Received: from thinkpad (unknown [192.168.3.118]) by promo.hnet.spb.ru (Postfix) with ESMTP id 7C61B1BAC95; Fri, 27 May 2005 17:04:27 +0400 (MSD) To: "'Derick Rethans'" Cc: "'Marcus Brg'" , "'Andi Gutmans'" , "'PHP Developers Mailing List'" Date: Fri, 27 May 2005 17:06:53 +0400 Message-ID: <000001c562bc$f781a690$8202a8c0@thinkpad> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.6626 Importance: Normal In-Reply-To: X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 Subject: RE: Another Interesting Reference Issue From: dmitry@zend.com ("Dmitry Stogov") References: Hi Derick, One for global $tree. One for stack. One for local $node. = 3 What is wrong? Thanks. Dmitry. > -----Original Message----- > From: Derick Rethans [mailto:derick@derickrethans.nl] > Sent: Friday, May 27, 2005 4:21 PM > To: dmitry@zend.com > Cc: Marcus Brg; Andi Gutmans; PHP Developers Mailing List > Subject: Another Interesting Reference Issue > > > Hello, > > I encountered a strange increase of the refcount with the following > script: > > error_reporting(E_ALL); > $tree = array ( > 1 => 'one', > 2 => 'two', > 3 => 'three' > ); > > function &find_node($key, &$node) > { > xdebug_debug_zval('node'); > $item =& $node[$key]; > return $item; > } > > $node =& find_node(3, $tree); > $node = 'drie'; > > The xdebug_debug_zval() function looks up the given symbol in > the symbol > table, and it prints it's refcount/is_ref value too (unlike the > debug_zval_dump() function available in PHP which actually modifies > those values). Logically you expect the refcount of $node to > be 2 (once > through the global var $tree, and once as local variable > $node. But the > refcount actually seems to be 3. > > I've been tracing things in the engine and found the following places > where the refcount of this variable is modified (file/line > nos are from > php 5.0-dev): > > Old value = 1 > New value = 2 > zend_send_ref_handler (execute_data=0xbfffd410, > opline=0x85f5440, op_array=0x85f0b64) at > /dat/dev/php/php-5.0dev/Zend/zend_execute.c:3077 > 3077 zend_ptr_stack_push(&EG(argument_stack), varptr); > (gdb) bt > #0 zend_send_ref_handler (execute_data=0xbfffd410, > opline=0x85f5440, op_array=0x85f0b64) > at /dat/dev/php/php-5.0dev/Zend/zend_execute.c:3077 > #1 0x0831de66 in execute (op_array=0x85f0b64) at > /dat/dev/php/php-5.0dev/Zend/zend_execute.c:1415 > > > Old value = 2 > New value = 3 > 0x0831c192 in zend_assign_to_variable_reference (result=0x0, > variable_ptr_ptr=0x85f74c8, value_ptr_ptr=0x85e4b8c, Ts=0x0) > at /dat/dev/php/php-5.0dev/Zend/zend_execute.c:262 > 262 value_ptr->refcount++; > (gdb) bt > #0 0x0831c192 in zend_assign_to_variable_reference > (result=0x0, variable_ptr_ptr=0x85f74c8, > value_ptr_ptr=0x85e4b8c, Ts=0x0) > at /dat/dev/php/php-5.0dev/Zend/zend_execute.c:262 > #1 0x083227d7 in zend_recv_handler (execute_data=0xbfffd1a0, > opline=0x85f63bc, op_array=0x85f7a18) > at /dat/dev/php/php-5.0dev/Zend/zend_execute.c:3109 > #2 0x0831de66 in execute (op_array=0x85f7a18) at > /dat/dev/php/php-5.0dev/Zend/zend_execute.c:1415 > > It does not matter if it's passed by reference or not - the value is > always 3 inside the function. What is the reason for this? > > regards, > Derick > > -- > Derick Rethans > http://derickrethans.nl | http://ez.no | http://xdebug.org > >