[PHP-DEV] PHP 4.0 Bug #2956: array_walk not working as it did in php 3.0? From: fvkuipers <email protected>
Date: 12/10/99

From: fvkuipers <email protected>
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

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
For additional commands, e-mail: php-dev-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>