php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43544 Inconsistent behaviour of array_walk_recursive () in PHP 5 and PHP 6.
Submitted: 2007-12-09 14:33 UTC Modified: 2007-12-10 09:44 UTC
From: dharma dot yp at in dot ibm dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.2CVS-2007-12-09 (snap) OS: Windows, Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dharma dot yp at in dot ibm dot com
New email:
PHP Version: OS:

 

 [2007-12-09 14:33 UTC] dharma dot yp at in dot ibm dot com
Description:
------------
In array_walk_recursive(), if we pass non-existent callback function then it gives following output
1)for PHP 5
Warning: array_walk_recursive(): Unable to call echo() - function does not exist in %s on line %d
bool(true)

    
2)for PHP 6
Warning: array_walk_recursive() : Expects parameter 2 to be valid callback, string given in %s on line %d
NULL

In PHP5, array_walk_recursive() gives warning message the number passed array element times, where as in PHP 6, it gives warning message only once with return value "NULL". This is an inconsistent behavior of array_walk_recursive() with PHP5 and PHP6.


The return value of " bool(true)" in PHP5 (1),  will misguide/confuse the developers as the documentation says array_walk_recursive() returns TRUE on Success and FALSE on Failure.

Reproduce code:
---------------
<?php

$input = array(array(1,2), array(3), array(4,5));

var_dump( array_walk_recursive($input, 'echo'));

?>


Expected result:
----------------
/***** for PHP5 ****/

Warning: array_walk_recursive(): Unable to call echo() - function does not exist in %s on line %d
bool(false)

/**** for PHP6 ****/
Warning: array_walk_recursive() : Expects parameter 2 to be valid callback, string given in %s on line %d
NULL


Actual result:
--------------
/**** for PHP5 ****/

Warning: array_walk_recursive(): Unable to call echo() - function does not exist in %s on line %d

Warning: array_walk_recursive(): Unable to call echo() - function does not exist in %s on line %d

Warning: array_walk_recursive(): Unable to call echo() - function does not exist in %s on line %d
bool(true)


/**** for PHP6 ****/
Warning: array_walk_recursive() : Expects parameter 2 to be valid callback, string given in %s on line %d
NULL


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-09 16:25 UTC] felipe@php.net
I'm afraid that is related:
http://bugs.php.net/bug.php?id=43231
 [2007-12-10 09:44 UTC] jani@php.net
5.2 and 6 are not consistent in many other ways too. 5.3 and 6 OTOH are more consistent, and this is acting same in both. 

Just don't try comparing 5.2 with anything above..
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 15:01:56 2024 UTC