Personally i prefer to redeclare the function if the existing function doesnt exist only once, as if you use the function alot there could be performance decrease for PHP5.
However, I have written a simple wrapper function here called "recursive_array_walk", which functions exactly the same as array_walk_recursive(). I also added in the same error checking and triggered errors as the real function:
PHP Code:
function recursive_array_walk( &$input, $funcname, $userdata = NULL ){
if( !function_exists( 'array_walk_recursive' ) ){
if( !is_array( $input ) ){
trigger_error( 'The argument should be an array', E_USER_WARNING );
return false;
}
foreach( $input as $key => $data ){
if( is_array( $data ) ){
if( false === recursive_array_walk( $input[$key], $funcname, $userdata ) ){
return false;
}
} else {
if( is_array( $funcname ) ){
$obj = $funcname[0];
$method = $funcname[1];
if( method_exists( $obj, $method ) ){
$obj->$method( $data, $key, $userdata );
} else {
trigger_error( 'Unable to call ' . get_class($obj) . "::$method() - function does not exist", E_USER_WARNING );
return false;
}
} else {
if( function_exists( $funcname ) ){
$funcname( $data, $key, $userdata );
} else {
trigger_error( "Unable to call $funcname() - function does not exist", E_USER_WARNING );
return false;
}
}
}
}
} else {
return array_walk_recursive( $input, $funcname, $userdata );
}
}