note 56135 added to language.references.whatdo

From: Date: Wed, 24 Aug 2005 16:15:17 +0000
Subject: note 56135 added to language.references.whatdo
Groups: php.notes 
Request: Send a blank email to php-notes+get-94134@lists.php.net to get a copy of this message
Example 21-3 says that using references in "complex arrays" may not work as expected. But I have found a way around it, to get normal reference behavior. Compare the output of these two scripts: <?php for ( $i = 0; $i < 10; $i ++ ) $top[$i] = &$top; $top['A'] = 'AAAAA'; var_dump( $top ); ?> <?php $z = &$top; for ( $i = 0; $i < 10; $i ++ ) $top[$i] = &$top; $top['A'] = 'AAAAA'; var_dump( $top ); ?> Running PHP 5.0, the first generates about 157457 lines while the second only generates 2554 lines. The only difference in the code is setting an initial reference before adding self-references inside the array. This simple step prevents the array from being duplicated every time another self-reference is added. I am not sure if the duplication is intentional or if it's a bug in the way references are created, but the docs certainly recognize it. ---- Manual Page -- http://www.php.net/manual/en/language.references.whatdo.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56135 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56135&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56135&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56135&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56135&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56135&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56135&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56135&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#94134) next »