PHP 4.0 Bug #2956: array_walk not working as it did in php 3.0?
| From: | fvkuipers at home dot com | Date: | Sat, 11 Dec 1999 01:54:43 +0000 |
| Subject: | PHP 4.0 Bug #2956: array_walk not working as it did in php 3.0? | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-13571@lists.php.net to get a copy of this message | ||
From: fvkuipers@home.com
Operating system: Linux (Red Hat 6)
PHP version: 4.0 Beta 3
PHP Bug Type: Misbehaving function
Bug description: array_walk not working as it did in php 3.0?
This example is taken from the php3 documentation, and works in php3:
$fruits =
array("d"=>"lemon","a"=>"orange","b"=>"banana","c"=>"apple");
function test_alter( &$item1 ) {
$item1 = 'bogus';
}
function test_print( $item2 ) {
echo "$item2<br>\n";
}
array_walk( $fruits, 'test_print' );
array_walk( $fruits, 'test_alter' );
array_walk( $fruits, 'test_print' );
When I run this, I get the following and NOTHING else:
lemon<br>
orange<br>
banana<br>
apple<br>
It seems that the array is traversed the first time, but not the next two times... perhaps it needs
to restore the array pointer?? See the modification to this code:
// The functions 'test_print' and 'test_alter' are as defined above...
// [snip]
array_walk( $fruits, 'test_print' );
reset($fruits);
array_walk( $fruits, 'test_alter' );
reset($fruits);
array_walk( $fruits, 'test_print' );
This produces the expected output of:
lemon<br>
orange<br>
banana<br>
apple<br>
bogus<br>
bogus<br>
bogus<br>
bogus<br>
This is the result of the first file I've worked on under php4... so there may be more bugs on
the way! HTH.
Fred