Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:16300 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 82760 invoked by uid 1010); 27 May 2005 12:24:20 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 74292 invoked from network); 27 May 2005 12:21:08 -0000 Received: from unknown (HELO derickrethans.nl) (127.0.0.1) by localhost with SMTP; 27 May 2005 12:21:08 -0000 X-Host-Fingerprint: 82.94.239.5 unknown Linux 2.5 (sometimes 2.4) (4) Received: from ([82.94.239.5:53189] helo=jdi.jdi-ict.nl) by pb1.pair.com (ecelerity 1.2 r(5656M)) with SMTP id 3E/03-15978-2B017924 for ; Fri, 27 May 2005 08:21:07 -0400 Received: from localhost (localhost [127.0.0.1]) by jdi.jdi-ict.nl (8.12.11/8.12.11) with ESMTP id j4RCPxPI030692 for ; Fri, 27 May 2005 14:25:59 +0200 Received: from localhost (localhost [127.0.0.1]) by jdi.jdi-ict.nl (8.12.11/8.12.11) with ESMTP id j4RCPvYJ030677; Fri, 27 May 2005 14:25:57 +0200 Date: Fri, 27 May 2005 14:20:58 +0200 (CEST) X-X-Sender: derick@localhost To: dmitry@zend.com cc: =?utf-8?Q?Marcus_B=F6rger?= , Andi Gutmans , PHP Developers Mailing List Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at jci-ict.nl Subject: Another Interesting Reference Issue From: derick@derickrethans.nl (Derick Rethans) Hello, I encountered a strange increase of the refcount with the following script: '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