Bug #11937 Updated: Clarification of $foo = new Class and $foo = &new Class

From: Date: Wed, 12 Dec 2001 22:09:04 +0000
Subject: Bug #11937 Updated: Clarification of $foo = new Class and $foo = &new Class
References: 1  Groups: php.dev php.doc 
Request: Send a blank email to php-dev+get-73405@lists.php.net to get a copy of this message
ID: 11937 Updated by: jan Reported By: phil3k@aon.at Old Summary: Bug in array handling Old Status: Assigned Status: Closed Bug Type: Documentation problem Old Operating System: Windows 98 Operating System: Any Old PHP Version: 4.0.5 PHP Version: 4.0 Latest CVS (2001-06-27) Old Assigned To: jeroen Assigned To: New Comment: fixed in CVS. Previous Comments: ------------------------------------------------------------------------ [2001-07-07 09:10:37] jeroen@php.net Should be more clear in the docs. It is only implicitely there. Assigning to myself. ------------------------------------------------------------------------ [2001-07-06 15:20:01] vlad@php.net If you unset an element in the array, it does not make the whole array shift so it starts from index zero again. That's normal behaviour. ------------------------------------------------------------------------ [2001-07-06 14:52:11] phil3k@aon.at <?php //Two elements in an Array $array[] = "Maria"; $array[] = "Lisa"; //just a test output array_walk ($array, "my_print"); //and then free the first element of the array unset ($array[0]); function my_print ($value) { print $value . " "; } print "<br />"; //The following dump will produce: //array(1) { [1]=> string(4) "Lisa" } //This means that the first element has the index 1 //But it should have index 0 var_dump ($array); ?> If you have more than two elements, and you free one of them, you can just prevent this bug, by resorting the array with any sort function. But with only two elements, this won't work, and if you clear the first of these, you will get the same result as I have got, there was one element, but with the wrong index. ------------------------------------------------------------------------ Edit this bug report at http://bugs.php.net/?id=11937&edit=1

« previous php.dev (#73405) next »