]> granicus.if.org Git - php/commitdiff
New testcases for array_walk() function
authorRaghubansh Kumar <kraghuba@php.net>
Tue, 11 Dec 2007 10:50:17 +0000 (10:50 +0000)
committerRaghubansh Kumar <kraghuba@php.net>
Tue, 11 Dec 2007 10:50:17 +0000 (10:50 +0000)
30 files changed:
ext/standard/tests/array/array_walk_basic1.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_basic2.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_error1.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_error2.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_object1.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_object2.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_recursive_basic1.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_recursive_basic2.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_recursive_error1.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_recursive_error2.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_recursive_object1.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_recursive_object2.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_recursive_variation1.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_recursive_variation2.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_recursive_variation3.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_recursive_variation4.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_recursive_variation5.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_recursive_variation6.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_recursive_variation7.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_recursive_variation8.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_recursive_variation9.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_variation1.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_variation2.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_variation3.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_variation4.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_variation5.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_variation6.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_variation7.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_variation8.phpt [new file with mode: 0644]
ext/standard/tests/array/array_walk_variation9.phpt [new file with mode: 0644]

diff --git a/ext/standard/tests/array/array_walk_basic1.phpt b/ext/standard/tests/array/array_walk_basic1.phpt
new file mode 100644 (file)
index 0000000..34e8e88
--- /dev/null
@@ -0,0 +1,80 @@
+--TEST--
+Test array_walk() function : basic functionality - regular array
+--FILE--
+<?php
+/* Prototype  : bool array_walk(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+echo "*** Testing array_walk() : basic functionality ***\n";
+
+// regular array
+$fruits = array("lemon", "orange", "banana", "apple");
+
+/*  Prototype : test_print(mixed $item, mixed $key)
+ *  Parameters : item - item in key/item pair 
+ *               key - key in key/item pair
+ *  Description : prints the array values with keys
+ */
+function test_print($item, $key)
+{
+   // dump the arguments to check that they are passed
+   // with proper type
+   var_dump($item); // value 
+   var_dump($key);  // key 
+   echo "\n"; // new line to separate the output between each element
+}
+function with_userdata($item, $key, $user_data)
+{
+   // dump the arguments to check that they are passed
+   // with proper type
+   var_dump($item); // value 
+   var_dump($key);  // key 
+   var_dump($user_data); // user supplied data
+   echo "\n"; // new line to separate the output between each element
+}
+
+echo "-- Using array_walk() with default parameters to show array contents --\n";
+var_dump( array_walk($fruits, 'test_print'));
+
+echo "-- Using array_walk() with all parameters --\n";
+var_dump( array_walk($fruits, 'with_userdata', "Added"));
+
+echo "Done";
+?>
+--EXPECT--
+*** Testing array_walk() : basic functionality ***
+-- Using array_walk() with default parameters to show array contents --
+string(5) "lemon"
+int(0)
+
+string(6) "orange"
+int(1)
+
+string(6) "banana"
+int(2)
+
+string(5) "apple"
+int(3)
+
+bool(true)
+-- Using array_walk() with all parameters --
+string(5) "lemon"
+int(0)
+string(5) "Added"
+
+string(6) "orange"
+int(1)
+string(5) "Added"
+
+string(6) "banana"
+int(2)
+string(5) "Added"
+
+string(5) "apple"
+int(3)
+string(5) "Added"
+
+bool(true)
+Done
\ No newline at end of file
diff --git a/ext/standard/tests/array/array_walk_basic2.phpt b/ext/standard/tests/array/array_walk_basic2.phpt
new file mode 100644 (file)
index 0000000..e856b58
--- /dev/null
@@ -0,0 +1,105 @@
+--TEST--
+Test array_walk() function : basic functionality - associative array
+--FILE--
+<?php
+/* Prototype  : bool array_walk(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+echo "*** Testing array_walk() : basic functionality ***\n";
+
+// associative array
+$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
+
+// User defined callback functions
+/*  Prototype : test_alter(mixed $item, mixed $key, string $prefix)
+ *  Parameters : item - value in key/value pair 
+ *               key - key in key/value pair
+ *               prefix - string to be added 
+ *  Description : alters the array values by appending prefix string
+ */ 
+function test_alter(&$item, $key, $prefix)
+{
+  // dump the arguments to check that they are passed
+  // with proper type
+  var_dump($item); // value
+  var_dump($key);  // key
+  var_dump($prefix); // additional agument passed to callback function
+  echo "\n"; // new line to separate the output between each element
+}
+
+/*  Prototype : test_print(mixed $item, mixed $key)
+ *  Parameters : item - value in key/value pair 
+ *               key - key in key/value pair
+ *  Description : prints the array values with keys
+ */
+function test_print($item, $key)
+{
+  // dump the arguments to check that they are passed
+  // with proper type
+  var_dump($item); // value
+  var_dump($key);  // key
+  echo "\n"; // new line to separate the output between each element
+}
+
+echo "-- Using array_walk with default parameters to show array contents --\n";
+var_dump(array_walk($fruits, 'test_print'));
+
+echo "-- Using array_walk with one optional parameter to modify contents --\n";
+var_dump (array_walk($fruits, 'test_alter', 'fruit'));
+
+echo "-- Using array_walk with default parameters to show modified array contents --\n";
+var_dump (array_walk($fruits, 'test_print'));
+
+echo "Done";
+?>
+--EXPECT--
+*** Testing array_walk() : basic functionality ***
+-- Using array_walk with default parameters to show array contents --
+string(5) "lemon"
+string(1) "d"
+
+string(6) "orange"
+string(1) "a"
+
+string(6) "banana"
+string(1) "b"
+
+string(5) "apple"
+string(1) "c"
+
+bool(true)
+-- Using array_walk with one optional parameter to modify contents --
+string(5) "lemon"
+string(1) "d"
+string(5) "fruit"
+
+string(6) "orange"
+string(1) "a"
+string(5) "fruit"
+
+string(6) "banana"
+string(1) "b"
+string(5) "fruit"
+
+string(5) "apple"
+string(1) "c"
+string(5) "fruit"
+
+bool(true)
+-- Using array_walk with default parameters to show modified array contents --
+string(5) "lemon"
+string(1) "d"
+
+string(6) "orange"
+string(1) "a"
+
+string(6) "banana"
+string(1) "b"
+
+string(5) "apple"
+string(1) "c"
+
+bool(true)
+Done
diff --git a/ext/standard/tests/array/array_walk_error1.phpt b/ext/standard/tests/array/array_walk_error1.phpt
new file mode 100644 (file)
index 0000000..014885a
--- /dev/null
@@ -0,0 +1,48 @@
+--TEST--
+Test array_walk() function : error conditions
+--FILE--
+<?php
+/* Prototype  : bool array_walk(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+$input = array(1, 2);
+
+/* Prototype : callback(mixed value, mixed key, mixed user_data)
+ * Parameters : value - value in key/value pair
+ *              key - key in key/value pair
+ *              user_data - extra parameter
+ */
+function callback ($value, $key, $user_data) {
+  echo "\ncallback() invoked \n";
+}
+
+echo "*** Testing array_walk() : error conditions ***\n";
+
+echo "-- Testing array_walk() function with zero arguments --\n";
+var_dump( array_walk() );
+
+echo "-- Testing array_walk() function with one argument --\n";
+var_dump( array_walk($input) );
+
+echo "-- Testing array_walk() function with non existent callback function  --\n";
+var_dump( array_walk($input, "non_existent") );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_walk() : error conditions ***
+-- Testing array_walk() function with zero arguments --
+
+Warning: array_walk() expects at least 2 parameters, 0 given in %s on line %d
+NULL
+-- Testing array_walk() function with one argument --
+
+Warning: array_walk() expects at least 2 parameters, 1 given in %s on line %d
+NULL
+-- Testing array_walk() function with non existent callback function  --
+
+Warning: array_walk(): Unable to call non_existent() - function does not exist in %s on line %d
+bool(true)
+Done
diff --git a/ext/standard/tests/array/array_walk_error2.phpt b/ext/standard/tests/array/array_walk_error2.phpt
new file mode 100644 (file)
index 0000000..654637a
--- /dev/null
@@ -0,0 +1,59 @@
+--TEST--
+Test array_walk() function : error conditions - callback parameters
+--FILE--
+<?php
+/* Prototype  : bool array_walk(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Testing array_walk() by passing more number of parameters to callback function
+ */
+$input = array(1);
+
+function callback1($value, $key, $user_data ) {
+  echo "\ncallback1() invoked \n";
+}
+
+function callback2($value, $key, $user_data1, $user_data2) {
+  echo "\ncallback2() invoked \n";
+}
+echo "*** Testing array_walk() : error conditions - callback parameters ***\n";
+
+// expected: Missing argument Warning
+var_dump( array_walk($input, "callback1") );
+var_dump( array_walk($input, "callback2", 4) );
+
+// expected: Warning is supressed
+var_dump( @array_walk($input, "callback1") );  
+var_dump( @array_walk($input, "callback2", 4) );  
+
+echo "-- Testing array_walk() function with too many callback parameters --\n";
+var_dump( array_walk($input, "callback1", 20, 10) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_walk() : error conditions - callback parameters ***
+
+Warning: Missing argument 3 for callback1() in %s on line %d
+
+callback1() invoked 
+bool(true)
+
+Warning: Missing argument 4 for callback2() in %s on line %d
+
+callback2() invoked 
+bool(true)
+
+callback1() invoked 
+bool(true)
+
+callback2() invoked 
+bool(true)
+-- Testing array_walk() function with too many callback parameters --
+
+Warning: array_walk() expects at most 3 parameters, 4 given in %s on line %d
+NULL
+Done
diff --git a/ext/standard/tests/array/array_walk_object1.phpt b/ext/standard/tests/array/array_walk_object1.phpt
new file mode 100644 (file)
index 0000000..632b651
Binary files /dev/null and b/ext/standard/tests/array/array_walk_object1.phpt differ
diff --git a/ext/standard/tests/array/array_walk_object2.phpt b/ext/standard/tests/array/array_walk_object2.phpt
new file mode 100644 (file)
index 0000000..61d0529
--- /dev/null
@@ -0,0 +1,104 @@
+--TEST--
+Test array_walk() function : object functionality - array of objects
+--FILE--
+<?php
+/* Prototype  : bool array_walk(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+/*
+* Testing array_walk() with an array of objects
+*/
+
+echo "*** Testing array_walk() : array of objects ***\n";
+
+/*
+ * Prototype : callback(mixed $value, mixed $key, int $addvalue
+ * Parameters : $value - values in given input array
+ *              $key - keys in given input array
+ *              $addvalue - value to be added
+ * Description : Function adds the addvalue to each element of an array
+*/
+function callback_private($value, $key, $addValue)
+{ 
+  echo "value : ";
+  var_dump($value->getValue());
+  echo "key : ";
+  var_dump($key);
+}
+
+function callback_public($value, $key)
+{
+  echo "value : ";
+  var_dump($value->pub_value);
+}
+function callback_protected($value, $key)
+{
+  echo "value : ";
+  var_dump($value->get_pro_value());
+}
+
+class MyClass
+{
+  private $pri_value;
+  public $pub_value;
+  protected $pro_value;
+  public function __construct($setVal)
+  {
+    $this->pri_value = $setVal;
+    $this->pub_value = $setVal;
+    $this->pro_value = $setVal;
+  }
+  public function getValue()
+  {
+    return $this->pri_value;
+  }
+  public function get_pro_value()
+  {
+    return $this->pro_value;
+  }
+};    
+
+// array containing objects of MyClass
+$input = array (
+  new MyClass(3),
+  new MyClass(10),
+  new MyClass(20),
+  new MyClass(-10)
+);
+
+echo "-- For private member --\n";
+var_dump( array_walk($input, "callback_private", 1));
+echo "-- For public member --\n";
+var_dump( array_walk($input, "callback_public"));
+echo "-- For protected member --\n";
+var_dump( array_walk($input, "callback_protected")); 
+
+echo "Done"
+?>
+--EXPECTF--
+*** Testing array_walk() : array of objects ***
+-- For private member --
+value : int(3)
+key : int(0)
+value : int(10)
+key : int(1)
+value : int(20)
+key : int(2)
+value : int(-10)
+key : int(3)
+bool(true)
+-- For public member --
+value : int(3)
+value : int(10)
+value : int(20)
+value : int(-10)
+bool(true)
+-- For protected member --
+value : int(3)
+value : int(10)
+value : int(20)
+value : int(-10)
+bool(true)
+Done
diff --git a/ext/standard/tests/array/array_walk_recursive_basic1.phpt b/ext/standard/tests/array/array_walk_recursive_basic1.phpt
new file mode 100644 (file)
index 0000000..df192b6
--- /dev/null
@@ -0,0 +1,80 @@
+--TEST--
+Test array_walk_recursive() function : basic functionality - regular array
+--FILE--
+<?php
+/* Prototype  : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+echo "*** Testing array_walk_recursive() : basic functionality ***\n";
+
+// regular array
+$fruits = array("lemon", array("orange", "banana"), array("apple"));
+
+/*  Prototype : test_print(mixed $item, mixed $key)
+ *  Parameters : item - item in key/item pair 
+ *               key - key in key/item pair
+ *  Description : prints the array values with keys
+ */
+function test_print($item, $key)
+{
+   // dump the arguments to check that they are passed
+   // with proper type
+   var_dump($item); // value 
+   var_dump($key);  // key 
+   echo "\n"; // new line to separate the output between each element
+}
+function with_userdata($item, $key, $user_data)
+{
+   // dump the arguments to check that they are passed
+   // with proper type
+   var_dump($item); // value 
+   var_dump($key);  // key 
+   var_dump($user_data); // user supplied data
+   echo "\n"; // new line to separate the output between each element
+}
+
+echo "-- Using array_walk_recursive() with default parameters to show array contents --\n";
+var_dump( array_walk_recursive($fruits, 'test_print'));
+
+echo "-- Using array_walk_recursive() with all parameters --\n";
+var_dump( array_walk_recursive($fruits, 'with_userdata', "Added"));
+
+echo "Done";
+?>
+--EXPECT--
+*** Testing array_walk_recursive() : basic functionality ***
+-- Using array_walk_recursive() with default parameters to show array contents --
+string(5) "lemon"
+int(0)
+
+string(6) "orange"
+int(0)
+
+string(6) "banana"
+int(1)
+
+string(5) "apple"
+int(0)
+
+bool(true)
+-- Using array_walk_recursive() with all parameters --
+string(5) "lemon"
+int(0)
+string(5) "Added"
+
+string(6) "orange"
+int(0)
+string(5) "Added"
+
+string(6) "banana"
+int(1)
+string(5) "Added"
+
+string(5) "apple"
+int(0)
+string(5) "Added"
+
+bool(true)
+Done
diff --git a/ext/standard/tests/array/array_walk_recursive_basic2.phpt b/ext/standard/tests/array/array_walk_recursive_basic2.phpt
new file mode 100644 (file)
index 0000000..c71d92b
--- /dev/null
@@ -0,0 +1,105 @@
+--TEST--
+Test array_walk_recursive() function : basic functionality - associative array
+--FILE--
+<?php
+/* Prototype  : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+echo "*** Testing array_walk_recursive() : basic functionality ***\n";
+
+// associative array
+$fruits = array("a" => "lemon", "b" => array( "c" => "orange", "d" => "banana"), "e" => array("f" => "apple"));
+
+// User defined callback functions
+/*  Prototype : test_alter(mixed $item, mixed $key, string $prefix)
+ *  Parameters : item - value in key/value pair 
+ *               key - key in key/value pair
+ *               prefix - string to be added 
+ *  Description : alters the array values by appending prefix string
+ */ 
+function test_alter(&$item, $key, $prefix)
+{
+  // dump the arguments to check that they are passed
+  // with proper type
+  var_dump($item); // value
+  var_dump($key);  // key
+  var_dump($prefix); // additional agument passed to callback function
+  echo "\n"; // new line to separate the output between each element
+}
+
+/*  Prototype : test_print(mixed $item, mixed $key)
+ *  Parameters : item - value in key/value pair 
+ *               key - key in key/value pair
+ *  Description : prints the array values with keys
+ */
+function test_print($item, $key)
+{
+  // dump the arguments to check that they are passed
+  // with proper type
+  var_dump($item); // value
+  var_dump($key);  // key
+  echo "\n"; // new line to separate the output between each element
+}
+
+echo "-- Using array_walk_recursive with default parameters to show array contents --\n";
+var_dump(array_walk_recursive($fruits, 'test_print'));
+
+echo "-- Using array_walk_recursive with one optional parameter to modify contents --\n";
+var_dump (array_walk_recursive($fruits, 'test_alter', 'fruit'));
+
+echo "-- Using array_walk_recursive with default parameters to show modified array contents --\n";
+var_dump (array_walk_recursive($fruits, 'test_print'));
+
+echo "Done";
+?>
+--EXPECT--
+*** Testing array_walk_recursive() : basic functionality ***
+-- Using array_walk_recursive with default parameters to show array contents --
+string(5) "lemon"
+string(1) "a"
+
+string(6) "orange"
+string(1) "c"
+
+string(6) "banana"
+string(1) "d"
+
+string(5) "apple"
+string(1) "f"
+
+bool(true)
+-- Using array_walk_recursive with one optional parameter to modify contents --
+string(5) "lemon"
+string(1) "a"
+string(5) "fruit"
+
+string(6) "orange"
+string(1) "c"
+string(5) "fruit"
+
+string(6) "banana"
+string(1) "d"
+string(5) "fruit"
+
+string(5) "apple"
+string(1) "f"
+string(5) "fruit"
+
+bool(true)
+-- Using array_walk_recursive with default parameters to show modified array contents --
+string(5) "lemon"
+string(1) "a"
+
+string(6) "orange"
+string(1) "c"
+
+string(6) "banana"
+string(1) "d"
+
+string(5) "apple"
+string(1) "f"
+
+bool(true)
+Done
diff --git a/ext/standard/tests/array/array_walk_recursive_error1.phpt b/ext/standard/tests/array/array_walk_recursive_error1.phpt
new file mode 100644 (file)
index 0000000..df7092c
--- /dev/null
@@ -0,0 +1,48 @@
+--TEST--
+Test array_walk_recursive() function : error conditions
+--FILE--
+<?php
+/* Prototype  : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+$input = array(1, 2);
+
+/* Prototype : callback(mixed value, mixed key, mixed user_data)
+ * Parameters : value - value in key/value pair
+ *              key - key in key/value pair
+ *              user_data - extra parameter
+ */
+function callback ($value, $key, $user_data) {
+  echo "\ncallback() invoked \n";
+}
+
+echo "*** Testing array_walk_recursive() : error conditions ***\n";
+
+echo "-- Testing array_walk_recursive() function with zero arguments --\n";
+var_dump( array_walk_recursive() );
+
+echo "-- Testing array_walk_recursive() function with one argument --\n";
+var_dump( array_walk_recursive($input) );
+
+echo "-- Testing array_walk_recursive() function with non existent callback function  --\n";
+var_dump( array_walk_recursive($input, "non_existent") );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_walk_recursive() : error conditions ***
+-- Testing array_walk_recursive() function with zero arguments --
+
+Warning: array_walk_recursive() expects at least 2 parameters, 0 given in %s on line %d
+NULL
+-- Testing array_walk_recursive() function with one argument --
+
+Warning: array_walk_recursive() expects at least 2 parameters, 1 given in %s on line %d
+NULL
+-- Testing array_walk_recursive() function with non existent callback function  --
+
+Warning: array_walk_recursive(): Unable to call non_existent() - function does not exist in %s on line %d
+bool(true)
+Done
diff --git a/ext/standard/tests/array/array_walk_recursive_error2.phpt b/ext/standard/tests/array/array_walk_recursive_error2.phpt
new file mode 100644 (file)
index 0000000..d628e93
--- /dev/null
@@ -0,0 +1,59 @@
+--TEST--
+Test array_walk_recursive() function : error conditions - callback parameters
+--FILE--
+<?php
+/* Prototype  : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Testing array_walk_recursive() by passing more number of parameters to callback function
+ */
+$input = array(1);
+
+function callback1($value, $key, $user_data ) {
+  echo "\ncallback1() invoked \n";
+}
+
+function callback2($value, $key, $user_data1, $user_data2) {
+  echo "\ncallback2() invoked \n";
+}
+echo "*** Testing array_walk_recursive() : error conditions - callback parameters ***\n";
+
+// expected: Missing argument Warning
+var_dump( array_walk_recursive($input, "callback1") );
+var_dump( array_walk_recursive($input, "callback2", 4) );
+
+// expected: Warning is supressed
+var_dump( @array_walk_recursive($input, "callback1") );  
+var_dump( @array_walk_recursive($input, "callback2", 4) );  
+
+echo "-- Testing array_walk_recursive() function with too many callback parameters --\n";
+var_dump( array_walk_recursive($input, "callback1", 20, 10) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_walk_recursive() : error conditions - callback parameters ***
+
+Warning: Missing argument 3 for callback1() in %s on line %d
+
+callback1() invoked 
+bool(true)
+
+Warning: Missing argument 4 for callback2() in %s on line %d
+
+callback2() invoked 
+bool(true)
+
+callback1() invoked 
+bool(true)
+
+callback2() invoked 
+bool(true)
+-- Testing array_walk_recursive() function with too many callback parameters --
+
+Warning: array_walk_recursive() expects at most 3 parameters, 4 given in %s on line %d
+NULL
+Done
diff --git a/ext/standard/tests/array/array_walk_recursive_object1.phpt b/ext/standard/tests/array/array_walk_recursive_object1.phpt
new file mode 100644 (file)
index 0000000..30d03a7
Binary files /dev/null and b/ext/standard/tests/array/array_walk_recursive_object1.phpt differ
diff --git a/ext/standard/tests/array/array_walk_recursive_object2.phpt b/ext/standard/tests/array/array_walk_recursive_object2.phpt
new file mode 100644 (file)
index 0000000..aa12fe8
--- /dev/null
@@ -0,0 +1,106 @@
+--TEST--
+Test array_walk_recursive() function : object functionality - array of objects
+--FILE--
+<?php
+/* Prototype  : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+/*
+* Testing array_walk_recursive() with an array of objects
+*/
+
+echo "*** Testing array_walk_recursive() : array of objects ***\n";
+
+/*
+ * Prototype : callback(mixed $value, mixed $key, int $addvalue
+ * Parameters : $value - values in given input array
+ *              $key - keys in given input array
+ *              $addvalue - value to be added
+ * Description : Function adds the addvalue to each element of an array
+*/
+function callback_private($value, $key, $addValue)
+{ 
+  echo "value : ";
+  var_dump($value->getValue());
+  echo "key : ";
+  var_dump($key);
+}
+
+function callback_public($value, $key)
+{
+  echo "value : ";
+  var_dump($value->pub_value);
+}
+function callback_protected($value, $key)
+{
+  echo "value : ";
+  var_dump($value->get_pro_value());
+}
+
+class MyClass
+{
+  private $pri_value;
+  public $pub_value;
+  protected $pro_value;
+  public function __construct($setVal)
+  {
+    $this->pri_value = $setVal;
+    $this->pub_value = $setVal;
+    $this->pro_value = $setVal;
+  }
+  public function getValue()
+  {
+    return $this->pri_value;
+  }
+  public function get_pro_value()
+  {
+    return $this->pro_value;
+  }
+};    
+
+// array containing objects of MyClass
+$input = array (
+  array(
+  new MyClass(3),
+  new MyClass(10),
+  ),
+  new MyClass(20),
+  array(new MyClass(-10))
+);
+
+echo "-- For private member --\n";
+var_dump( array_walk_recursive($input, "callback_private", 1));
+echo "-- For public member --\n";
+var_dump( array_walk_recursive($input, "callback_public"));
+echo "-- For protected member --\n";
+var_dump( array_walk_recursive($input, "callback_protected")); 
+
+echo "Done"
+?>
+--EXPECTF--
+*** Testing array_walk_recursive() : array of objects ***
+-- For private member --
+value : int(3)
+key : int(0)
+value : int(10)
+key : int(1)
+value : int(20)
+key : int(1)
+value : int(-10)
+key : int(0)
+bool(true)
+-- For public member --
+value : int(3)
+value : int(10)
+value : int(20)
+value : int(-10)
+bool(true)
+-- For protected member --
+value : int(3)
+value : int(10)
+value : int(20)
+value : int(-10)
+bool(true)
+Done
diff --git a/ext/standard/tests/array/array_walk_recursive_variation1.phpt b/ext/standard/tests/array/array_walk_recursive_variation1.phpt
new file mode 100644 (file)
index 0000000..2673df9
--- /dev/null
@@ -0,0 +1,250 @@
+--TEST--
+Test array_walk_recursive() function : usage variations - unexpected values for 'input' argument 
+--FILE--
+<?php
+/* Prototype  : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Passing different scalar/nonscalar values in place of 'input' argument
+*/
+
+echo "*** Testing array_walk_recursive() : unexpected values for 'input' argument ***\n";
+
+// callback function
+/* Prototype : callback(mixed $value, mixed $key)
+ * Parameters : $value - values given in input array
+ *              $key - keys given in input array
+ * Description : Function prints each element of an array with key
+ */
+function callback($value, $key)
+{
+  echo "key : ";
+  var_dump($key);
+  echo "value : ";
+  var_dump($value);
+}
+
+// extra parameter passed to array_walk_recursive()
+$user_data = 10;
+
+// get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get resource variable
+$fp = fopen(__FILE__, 'r');
+
+// different scalar/nonscalar values to be used in place of an 'input' argument
+$input_values = array(
+
+         // int data
+/* 1*/   0,
+         1,
+         12345,
+         -2345,
+
+         // float data
+/* 5*/   10.5,
+         -10.5,
+         10.1234567e8,
+         10.7654321E-8,
+         .5,
+
+         // null data
+/* 10*/  NULL,
+         null,
+
+         // boolean data
+/* 12*/  true,
+         false,
+         TRUE,
+         FALSE,
+
+         // empty data
+/* 16*/  "",
+         '', 
+
+         // string data
+/* 18*/  "string",
+         'string',
+
+         // resource data
+         $fp,
+
+         // undefined data
+         @$undefined_var,
+
+         // unset data
+/* 22*/  @$unset_var,
+);
+
+
+for($count = 0; $count < count($input_values); $count++) {
+  echo "-- Iteration ".($count + 1)." --\n";
+  var_dump( array_walk_recursive($input_values[$count], "callback") );
+  var_dump( array_walk_recursive($input_values[$count], "callback", $user_data) );
+}
+
+fclose($fp);
+echo "Done"
+?>
+--EXPECTF--
+*** Testing array_walk_recursive() : unexpected values for 'input' argument ***
+-- Iteration 1 --
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 2 --
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 3 --
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 4 --
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 5 --
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 6 --
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 7 --
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 8 --
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 9 --
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 10 --
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 11 --
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 12 --
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 13 --
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 14 --
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 15 --
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 16 --
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 17 --
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 18 --
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 19 --
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 20 --
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 21 --
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 22 --
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): The argument should be an array in %s on line %d
+bool(false)
+Done
diff --git a/ext/standard/tests/array/array_walk_recursive_variation2.phpt b/ext/standard/tests/array/array_walk_recursive_variation2.phpt
new file mode 100644 (file)
index 0000000..d946473
--- /dev/null
@@ -0,0 +1,271 @@
+--TEST--
+Test array_walk_recursive() function : usage variations - unexpected values in place of 'funcname' argument(Bug#43543)
+--FILE--
+<?php
+/* Prototype  : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Passing different scalar/nonscalar values in place of 'funcname' argument
+*/
+
+echo "*** Testing array_walk_recursive() : unexpected values for 'funcname' argument ***\n";
+
+$input = array(1, array(2, 3));
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+$user_data = 20;
+
+// get resource variable
+$fp = fopen(__FILE__, 'r');
+
+// class definition
+class MyClass
+{
+  public function __toString()
+  {
+    return 'object';
+  }
+}
+
+// different scalar/nonscalar values to be used in place of callback function
+$funcname_values = array(
+
+         // int data
+/* 1*/   0,
+         1,
+         12345,
+         -2345,
+
+         // float data
+/* 5*/   10.5,
+         -10.5,
+         10.1234567e8,
+         10.7654321E-8,
+         .5,
+
+         // array data
+/* 10*/  array(),
+         array(0),
+         array(1),
+         array('color' => 'red', 'item' => 'pen'),
+
+         // null data
+/* 14*/  NULL,
+         null,
+
+         // boolean data
+/* 16*/  true,
+         false,
+         TRUE,
+         FALSE,
+
+         // empty data
+/* 20*/  "",
+         '',
+
+         // object data
+         new MyClass(),
+
+         // resource data
+/* 23*/  $fp,
+
+         // undefined data
+         @$undefined_var,
+
+         // unset data
+/* 25*/  @$unset_var,
+);
+
+for($count = 0; $count < count($funcname_values); $count++) {
+  echo "-- Iteration ".($count + 1)." --\n";
+  var_dump( array_walk_recursive($input, $funcname_values[$count]) );
+  var_dump( array_walk_recursive($input, $funcname_values[$count], $user_data ));
+}
+
+fclose($fp);
+echo "Done"
+?>
+--EXPECTF--
+*** Testing array_walk_recursive() : unexpected values for 'funcname' argument ***
+-- Iteration 1 --
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 2 --
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 3 --
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 4 --
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 5 --
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 6 --
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 7 --
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 8 --
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 9 --
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 10 --
+
+Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d
+bool(true)
+
+Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d
+bool(true)
+-- Iteration 11 --
+
+Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d
+bool(true)
+
+Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d
+bool(true)
+-- Iteration 12 --
+
+Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d
+bool(true)
+
+Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d
+bool(true)
+-- Iteration 13 --
+
+Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d
+bool(true)
+
+Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d
+bool(true)
+-- Iteration 14 --
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 15 --
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 16 --
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 17 --
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 18 --
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 19 --
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 20 --
+
+Warning: array_walk_recursive(): Unable to call () - function does not exist in %s on line %d
+bool(true)
+
+Warning: array_walk_recursive(): Unable to call () - function does not exist in %s on line %d
+bool(true)
+-- Iteration 21 --
+
+Warning: array_walk_recursive(): Unable to call () - function does not exist in %s on line %d
+bool(true)
+
+Warning: array_walk_recursive(): Unable to call () - function does not exist in %s on line %d
+bool(true)
+-- Iteration 22 --
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 23 --
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 24 --
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 25 --
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d
+bool(false)
+Done
diff --git a/ext/standard/tests/array/array_walk_recursive_variation3.phpt b/ext/standard/tests/array/array_walk_recursive_variation3.phpt
new file mode 100644 (file)
index 0000000..747ba3b
--- /dev/null
@@ -0,0 +1,123 @@
+--TEST--
+Test array_walk_recursive() function : usage variations - 'input' array with different values
+--FILE--
+<?php
+/* Prototype  : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Testing array_walk_recursive() with following types of 'input' arrays:
+ *    integer, float, string, bool, null, empty & mixed
+*/
+
+// callback function
+/*
+ * Prototype : print_value(mixed $value, int $key, int $count)
+ * Parameters : $value - array entries(values)
+ *              $key - keys in given input array
+ *              $count - extra parameter used as an index
+ * Description : prints the array values with keys and count value
+ */
+function print_value($value, $key, $count)
+{
+  echo  $count." : ".$key." ".$value."\n";
+}
+
+echo "*** Testing array_walk_recursive() : 'input' array with different values***\n";
+
+// different arrays as input
+$input_values = array(
+  
+       // integer values
+/*1*/  array(array(1, 0, -10), array(023, -041), array(0x5A, 0X1F, -0x6E)),
+  
+       // float value 
+       array(array(3.4, 0.8, -2.9), array(6.25e2, 8.20E-3)),
+
+       // string values
+       array('Mango', array("Apple", 'Orange', "Lemon")),
+
+       // bool values
+/*4*/  array( array(true, false), array(TRUE, FALSE)),
+
+       // null values
+       array( array(null), array(NULL)),
+
+       // empty array
+       array(),
+
+       // binary array
+       array(b"binary"),
+
+       // mixed array
+/*8*/  array(16, 8.345, array("Fruits"), array(true, null), array(FALSE), array(-98, 0.005, 'banana'))
+);
+
+for($count = 0; $count < count($input_values); $count++) {
+  echo "\n-- Iteration ".($count + 1)." --\n";
+  var_dump( array_walk_recursive($input_values[$count], "print_value", $count+1));
+}  
+echo "Done"
+?>
+--EXPECTF--
+*** Testing array_walk_recursive() : 'input' array with different values***
+
+-- Iteration 1 --
+1 : 0 1
+1 : 1 0
+1 : 2 -10
+1 : 0 19
+1 : 1 -33
+1 : 0 90
+1 : 1 31
+1 : 2 -110
+bool(true)
+
+-- Iteration 2 --
+2 : 0 3.4
+2 : 1 0.8
+2 : 2 -2.9
+2 : 0 625
+2 : 1 0.0082
+bool(true)
+
+-- Iteration 3 --
+3 : 0 Mango
+3 : 0 Apple
+3 : 1 Orange
+3 : 2 Lemon
+bool(true)
+
+-- Iteration 4 --
+4 : 0 1
+4 : 1 
+4 : 0 1
+4 : 1 
+bool(true)
+
+-- Iteration 5 --
+5 : 0 
+5 : 0 
+bool(true)
+
+-- Iteration 6 --
+bool(true)
+
+-- Iteration 7 --
+7 : 0 binary
+bool(true)
+
+-- Iteration 8 --
+8 : 0 16
+8 : 1 8.345
+8 : 0 Fruits
+8 : 0 1
+8 : 1 
+8 : 0 
+8 : 0 -98
+8 : 1 0.005
+8 : 2 banana
+bool(true)
+Done
diff --git a/ext/standard/tests/array/array_walk_recursive_variation4.phpt b/ext/standard/tests/array/array_walk_recursive_variation4.phpt
new file mode 100644 (file)
index 0000000..4db3497
--- /dev/null
@@ -0,0 +1,76 @@
+--TEST--
+Test array_walk_recursive() function : usage variations - 'input' array with subarray
+--FILE--
+<?php
+/* Prototype  : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Testing array_walk_recursive() with an array having subarrays as elements 
+*/
+
+echo "*** Testing array_walk_recursive() : array with subarray ***\n";
+
+// callback function
+/* Prototype : callback(mixed $value, mixed $key)
+ * Parameters : $value - values in given 'input' array
+ *              $key - keys in given 'input' array
+ * Description : It prints the count of an array elements, passed as argument
+ */
+function callback($value, $key)
+{
+   // dump the arguments to check that they are passed
+   // with proper type
+   var_dump($key);  // key
+   var_dump($value); // value
+   echo "\n"; // new line to separate the output between each element
+}
+
+$input = array(
+  array(),
+  array(1),
+  array(1,2,3),
+  array("Mango", "Orange"),
+  array(array(1, 2, 3), array(1))
+);
+
+var_dump( array_walk_recursive( $input, "callback"));
+
+echo "Done"
+?>
+--EXPECTF--
+*** Testing array_walk_recursive() : array with subarray ***
+int(0)
+int(1)
+
+int(0)
+int(1)
+
+int(1)
+int(2)
+
+int(2)
+int(3)
+
+int(0)
+string(5) "Mango"
+
+int(1)
+string(6) "Orange"
+
+int(0)
+int(1)
+
+int(1)
+int(2)
+
+int(2)
+int(3)
+
+int(0)
+int(1)
+
+bool(true)
+Done
diff --git a/ext/standard/tests/array/array_walk_recursive_variation5.phpt b/ext/standard/tests/array/array_walk_recursive_variation5.phpt
new file mode 100644 (file)
index 0000000..688da57
--- /dev/null
@@ -0,0 +1,64 @@
+--TEST--
+Test array_walk_recursive() function : usage variations - 'input' argument containing reference variables
+--FILE--
+<?php
+/* Prototype  : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Testing array_walk_recursive() with an array having reference variables
+*/
+
+echo "*** Testing array_walk_recursive() : array with references ***\n";
+
+$value1 = 10;
+$value2 = -20;
+$value3 = &$value1;
+$value4 = 50;
+
+// 'input' array containing references to above variables
+$input = array(&$value1, array(&$value2, -35), array(&$value3, 0), array(&$value4));
+
+// callback function
+/* Prototype : callback(int $value, mixed $key)
+ * Parameters : $value - values in given input array
+ *              $key - keys in given input array
+ * Description : function checks for the value whether positive or negative and displays according to that
+ */
+function callback($value, $key)
+{
+   // dump the arguments to check that they are passed
+   // with proper type
+   var_dump($key);  // key
+   var_dump($value); // value
+   echo "\n"; // new line to separate the output between each element
+}
+
+var_dump( array_walk_recursive($input, "callback"));
+
+echo "Done"
+?>
+--EXPECTF--
+*** Testing array_walk_recursive() : array with references ***
+int(0)
+int(10)
+
+int(0)
+int(-20)
+
+int(1)
+int(-35)
+
+int(0)
+int(10)
+
+int(1)
+int(0)
+
+int(0)
+int(50)
+
+bool(true)
+Done
diff --git a/ext/standard/tests/array/array_walk_recursive_variation6.phpt b/ext/standard/tests/array/array_walk_recursive_variation6.phpt
new file mode 100644 (file)
index 0000000..554ade4
--- /dev/null
@@ -0,0 +1,147 @@
+--TEST--
+Test array_walk_recursive() function : usage variations - 'input' argument as diff. associative arrays
+--FILE--
+<?php
+/* Prototype  : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Passing 'input' argument as an associative array 
+ *    with Numeric & string keys
+*/
+
+echo "*** Testing array_walk_recursive() : 'input' as an associative array ***\n";
+
+// callback functions
+/* Prototype : for_numeric( int $value, int $key, int $user_data)
+ * Parameters : $value - value from key/value pair of the array 
+ *              $key - key from key/value pair of the array
+ *              $user_data - data to be added to 'value'
+ * Description : Function adds values with keys & user_data
+ */
+function for_numeric($value, $key, $user_data)
+{
+  // dump the input values to see if they are 
+  // passed with correct type
+  var_dump($key);
+  var_dump($value);
+  var_dump($user_data);
+  echo "\n"; // new line to separate the output between each element
+}
+
+/* Prototype : for_string( string $value, string $key)
+ * Parameters : $value - values in given input array
+ *              $key - keys in given input array
+ * Description : Function appends key to the value
+ */
+function for_string($value, $key)
+{
+  // dump the input values to see if they are 
+  // passed with correct type
+  var_dump($key);
+  var_dump($value);
+  echo "\n"; // new line to separate the output between each element
+}
+
+/* Prototype : for_mixed( mixed $value, mixed $key)
+ * Parameters : $value - values in given input array
+ *              $key - keys in given input array
+ * Description : Function displays each element of an array with keys
+ */
+function for_mixed($value, $key)
+{
+  // dump the input values to see if they are 
+  // passed with correct type
+  var_dump($key);
+  var_dump($value);
+  echo "\n"; // new line to separate the output between each element
+}
+
+// Numeric keys
+$input = array( 0 => array(1 => 25, 5 => 12, 0 => -80), 1 => array(-2 => 100, 5 => 30));
+echo "-- Associative array with numeric keys --\n";
+var_dump( array_walk_recursive($input, "for_numeric", 10));
+
+// String keys
+$input = array( "a" => "Apple", 'z' => array('b' => 'Bananna', "c" => "carrot"), 'x' => array('o' => "Orange"));
+echo "-- Associative array with string keys --\n";
+var_dump( array_walk_recursive($input, "for_string"));
+
+// binary keys
+$input = array( b"a" => "Apple", b"b" => "Banana");
+echo "-- Associative array with binary keys --\n";
+var_dump( array_walk_recursive($input, "for_string"));
+
+// Mixed keys - numeric/string
+$input = array( 0 => array(0 => 1, 1 => 2), "x" => array("a" => "Apple", "b" => "Banana"), 2 =>3);
+echo "-- Associative array with numeric/string keys --\n";
+var_dump( array_walk_recursive($input, "for_mixed"));
+
+echo "Done"
+?>
+--EXPECTF--
+*** Testing array_walk_recursive() : 'input' as an associative array ***
+-- Associative array with numeric keys --
+int(1)
+int(25)
+int(10)
+
+int(5)
+int(12)
+int(10)
+
+int(0)
+int(-80)
+int(10)
+
+int(-2)
+int(100)
+int(10)
+
+int(5)
+int(30)
+int(10)
+
+bool(true)
+-- Associative array with string keys --
+string(1) "a"
+string(5) "Apple"
+
+string(1) "b"
+string(7) "Bananna"
+
+string(1) "c"
+string(6) "carrot"
+
+string(1) "o"
+string(6) "Orange"
+
+bool(true)
+-- Associative array with binary keys --
+string(1) "a"
+string(5) "Apple"
+
+string(1) "b"
+string(6) "Banana"
+
+bool(true)
+-- Associative array with numeric/string keys --
+int(0)
+int(1)
+
+int(1)
+int(2)
+
+string(1) "a"
+string(5) "Apple"
+
+string(1) "b"
+string(6) "Banana"
+
+int(2)
+int(3)
+
+bool(true)
+Done
diff --git a/ext/standard/tests/array/array_walk_recursive_variation7.phpt b/ext/standard/tests/array/array_walk_recursive_variation7.phpt
new file mode 100644 (file)
index 0000000..0cdd6d2
--- /dev/null
@@ -0,0 +1,93 @@
+--TEST--
+Test array_walk_recursive() function : usage variations - anonymous callback function
+--FILE--
+<?php
+/* Prototype  : proto bool array_walk_recursive(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+/*
+* Passing anonymous(run-time) callback function with following variations:
+*   with one parameter
+*   two parameters
+*   three parameters
+*   extra parameters
+*   without parameters
+*/
+
+echo "*** Testing array_walk_recursive() : anonymous function as callback ***\n";
+
+$input = array( array(2, 5), array(10, 0));
+
+echo "-- Anonymous function with one argument --\n";
+var_dump( array_walk_recursive($input, create_function('$value', 'var_dump($value); echo "\n";')));
+
+echo "-- Anonymous function with two arguments --\n";
+var_dump( array_walk_recursive($input, create_function('$value, $key', 'var_dump($key); var_dump($value); echo "\n";')));
+
+echo "-- Anonymous function with three arguments --\n";
+var_dump( array_walk_recursive($input, create_function('$value, $key, $user_data', 'var_dump($key); var_dump($value); var_dump($user_data); echo "\n";'), 10));
+
+echo "-- Anonymous function with one more argument --\n";
+var_dump( array_walk_recursive($input, create_function('$value, $key, $user_data', 'var_dump($key); var_dump($value); var_dump($user_data); echo "\n";'), 20, 30)); 
+
+echo "-- Anonymous function with null argument --\n";
+var_dump( array_walk_recursive( $input, create_function(null, 'echo "1\n";')));
+echo "Done"
+?>
+--EXPECTF--
+*** Testing array_walk_recursive() : anonymous function as callback ***
+-- Anonymous function with one argument --
+int(2)
+
+int(5)
+
+int(10)
+
+int(0)
+
+bool(true)
+-- Anonymous function with two arguments --
+int(0)
+int(2)
+
+int(1)
+int(5)
+
+int(0)
+int(10)
+
+int(1)
+int(0)
+
+bool(true)
+-- Anonymous function with three arguments --
+int(0)
+int(2)
+int(10)
+
+int(1)
+int(5)
+int(10)
+
+int(0)
+int(10)
+int(10)
+
+int(1)
+int(0)
+int(10)
+
+bool(true)
+-- Anonymous function with one more argument --
+
+Warning: array_walk_recursive() expects at most 3 parameters, 4 given in %s on line %d
+NULL
+-- Anonymous function with null argument --
+1
+1
+1
+1
+bool(true)
+Done
diff --git a/ext/standard/tests/array/array_walk_recursive_variation8.phpt b/ext/standard/tests/array/array_walk_recursive_variation8.phpt
new file mode 100644 (file)
index 0000000..aa73912
--- /dev/null
@@ -0,0 +1,42 @@
+--TEST--
+Test array_walk_recursive() function : usage variations - buit-in function as callback
+--FILE--
+<?php
+/* Prototype  : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Passing different buit-in functionns as callback function
+ *    pow function
+ *    min function
+ *    echo language construct
+*/
+
+echo "*** Testing array_walk_recursive() : built-in function as callback ***\n";
+
+$input = array(array(1, 2));
+
+echo "-- With 'pow' built-in function --\n";
+var_dump( array_walk_recursive($input, 'pow'));
+
+echo "-- With 'min' built-in function --\n";
+var_dump( array_walk_recursive($input, "min"));
+
+echo "-- With 'echo' language construct --\n";
+var_dump( array_walk_recursive($input, "echo"));
+
+echo "Done"
+?>
+--EXPECTF--
+*** Testing array_walk_recursive() : built-in function as callback ***
+-- With 'pow' built-in function --
+bool(true)
+-- With 'min' built-in function --
+bool(true)
+-- With 'echo' language construct --
+
+Warning: array_walk_recursive(): Unable to call echo() - function does not exist in %s on line %d
+bool(true)
+Done
diff --git a/ext/standard/tests/array/array_walk_recursive_variation9.phpt b/ext/standard/tests/array/array_walk_recursive_variation9.phpt
new file mode 100644 (file)
index 0000000..f18fe24
--- /dev/null
@@ -0,0 +1,99 @@
+--TEST--
+Test array_walk_recursive() function : usage variations - different callback functions
+--FILE--
+<?php
+/* Prototype  : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Passing different types of callback functions to array_walk_recursive()
+ *   without parameters
+ *   with less and more parameters
+*/
+
+echo "*** Testing array_walk_recursive() : callback function variation ***\n";
+
+$input = array(array('Apple', 'Banana'), 'Mango', array('Orange'));
+
+echo "-- callback function with both parameters --\n";
+function callback_two_parameter($value, $key)
+{
+   // dump the arguments to check that they are passed
+   // with proper type
+   var_dump($key);  // key
+   var_dump($value); // value
+   echo "\n"; // new line to separate the output between each element
+}
+var_dump( array_walk_recursive($input, 'callback_two_parameter'));
+
+echo "-- callback function with only one parameter --\n";
+function callback_one_parameter($value)
+{
+   // dump the arguments to check that they are passed
+   // with proper type
+   var_dump($value); // value
+   echo "\n"; // new line to separate the output between each element
+}
+var_dump( array_walk_recursive($input, 'callback_one_parameter'));
+
+echo "-- callback function without parameters --\n";
+function callback_no_parameter()
+{
+  echo "callback3() called\n";
+}
+var_dump( array_walk_recursive($input, 'callback_no_parameter'));
+
+echo "-- passing one more parameter to function with two parameters --\n";
+var_dump( array_walk_recursive($input, 'callback_two_parameter', 10)); 
+
+echo "Done"
+?>
+--EXPECTF--
+*** Testing array_walk_recursive() : callback function variation ***
+-- callback function with both parameters --
+int(0)
+string(5) "Apple"
+
+int(1)
+string(6) "Banana"
+
+int(1)
+string(5) "Mango"
+
+int(0)
+string(6) "Orange"
+
+bool(true)
+-- callback function with only one parameter --
+string(5) "Apple"
+
+string(6) "Banana"
+
+string(5) "Mango"
+
+string(6) "Orange"
+
+bool(true)
+-- callback function without parameters --
+callback3() called
+callback3() called
+callback3() called
+callback3() called
+bool(true)
+-- passing one more parameter to function with two parameters --
+int(0)
+string(5) "Apple"
+
+int(1)
+string(6) "Banana"
+
+int(1)
+string(5) "Mango"
+
+int(0)
+string(6) "Orange"
+
+bool(true)
+Done
diff --git a/ext/standard/tests/array/array_walk_variation1.phpt b/ext/standard/tests/array/array_walk_variation1.phpt
new file mode 100644 (file)
index 0000000..e08c0d7
--- /dev/null
@@ -0,0 +1,250 @@
+--TEST--
+Test array_walk() function : usage variations - unexpected values for 'input' argument 
+--FILE--
+<?php
+/* Prototype  : bool array_walk(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Passing different scalar/nonscalar values in place of 'input' argument
+*/
+
+echo "*** Testing array_walk() : unexpected values for 'input' argument ***\n";
+
+// callback function
+/* Prototype : callback(mixed $value, mixed $key)
+ * Parameters : $value - values given in input array
+ *              $key - keys given in input array
+ * Description : Function prints each element of an array with key
+ */
+function callback($value, $key)
+{
+  echo "key : ";
+  var_dump($key);
+  echo "value : ";
+  var_dump($value);
+}
+
+// extra parameter passed to array_walk()
+$user_data = 10;
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get resource variable
+$fp = fopen(__FILE__, 'r');
+
+// different scalar/nonscalar values to be used in place of an 'input' argument
+$input_values = array(
+
+         // int data
+/* 1*/   0,
+         1,
+         12345,
+         -2345,
+
+         // float data
+/* 5*/   10.5,
+         -10.5,
+         10.1234567e8,
+         10.7654321E-8,
+         .5,
+
+         // null data
+/* 10*/  NULL,
+         null,
+
+         // boolean data
+/* 12*/  true,
+         false,
+         TRUE,
+         FALSE,
+
+         // empty data
+/* 16*/  "",
+         '', 
+
+         // string data
+/* 18*/  "string",
+         'string',
+
+         // resource data
+         $fp, 
+
+         // undefined data
+         @$undefined_var,
+
+         // unset data
+/* 22*/  @$unset_var,
+);
+
+
+for($count = 0; $count < count($input_values); $count++) {
+  echo "-- Iteration ".($count + 1)." --\n";
+  var_dump( array_walk($input_values[$count], "callback") );
+  var_dump( array_walk($input_values[$count], "callback", $user_data) );
+}
+
+fclose($fp);
+echo "Done"
+?>
+--EXPECTF--
+*** Testing array_walk() : unexpected values for 'input' argument ***
+-- Iteration 1 --
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 2 --
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 3 --
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 4 --
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 5 --
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 6 --
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 7 --
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 8 --
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 9 --
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 10 --
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 11 --
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 12 --
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 13 --
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 14 --
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 15 --
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 16 --
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 17 --
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 18 --
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 19 --
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 20 --
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 21 --
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+-- Iteration 22 --
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+
+Warning: array_walk(): The argument should be an array in %s on line %d
+bool(false)
+Done
diff --git a/ext/standard/tests/array/array_walk_variation2.phpt b/ext/standard/tests/array/array_walk_variation2.phpt
new file mode 100644 (file)
index 0000000..88fbbf3
--- /dev/null
@@ -0,0 +1,271 @@
+--TEST--
+Test array_walk() function : usage variations - unexpected values in place of 'funcname' argument
+--FILE--
+<?php
+/* Prototype  : bool array_walk(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Passing different scalar/nonscalar values in place of 'funcname' argument
+*/
+
+echo "*** Testing array_walk() : unexpected values for 'funcname' argument ***\n";
+
+$input = array(1, 2);
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+$user_data = 20;
+
+// get resource variable
+$fp = fopen(__FILE__, 'r');
+
+// class definition
+class MyClass
+{
+  public function __toString()
+  {
+    return 'object';
+  }
+}
+
+// different scalar/nonscalar values to be used in place of callback function
+$funcname_values = array(
+
+         // int data
+/* 1*/   0,
+         1,
+         12345,
+         -2345,
+
+         // float data
+/* 5*/   10.5,
+         -10.5,
+         10.1234567e8,
+         10.7654321E-8,
+         .5,
+
+         // array data
+/* 10*/  array(),
+         array(0),
+         array(1),
+         array('color' => 'red', 'item' => 'pen'),
+
+         // null data
+/* 14*/  NULL,
+         null,
+
+         // boolean data
+/* 16*/  true,
+         false,
+         TRUE,
+         FALSE,
+
+         // empty data
+/* 20*/  "",
+         '',
+
+         // object data
+         new MyClass(),
+
+         // resource data
+/* 23*/  $fp, 
+
+         // undefined data
+         @$undefined_var,
+
+         // unset data
+/* 25*/  @$unset_var,
+);
+
+for($count = 0; $count < count($funcname_values); $count++) {
+  echo "-- Iteration ".($count + 1)." --\n";
+  var_dump( array_walk($input, $funcname_values[$count]) );
+  var_dump( array_walk($input, $funcname_values[$count], $user_data ));
+}
+
+fclose($fp);
+echo "Done"
+?>
+--EXPECTF--
+*** Testing array_walk() : unexpected values for 'funcname' argument ***
+-- Iteration 1 --
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 2 --
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 3 --
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 4 --
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 5 --
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 6 --
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 7 --
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 8 --
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 9 --
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 10 --
+
+Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d
+bool(true)
+
+Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d
+bool(true)
+-- Iteration 11 --
+
+Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d
+bool(true)
+
+Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d
+bool(true)
+-- Iteration 12 --
+
+Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d
+bool(true)
+
+Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d
+bool(true)
+-- Iteration 13 --
+
+Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d
+bool(true)
+
+Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d
+bool(true)
+-- Iteration 14 --
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 15 --
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 16 --
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 17 --
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 18 --
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 19 --
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 20 --
+
+Warning: array_walk(): Unable to call () - function does not exist in %s on line %d
+bool(true)
+
+Warning: array_walk(): Unable to call () - function does not exist in %s on line %d
+bool(true)
+-- Iteration 21 --
+
+Warning: array_walk(): Unable to call () - function does not exist in %s on line %d
+bool(true)
+
+Warning: array_walk(): Unable to call () - function does not exist in %s on line %d
+bool(true)
+-- Iteration 22 --
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 23 --
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 24 --
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+-- Iteration 25 --
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+
+Warning: array_walk(): Wrong syntax for function name in %s on line %d
+bool(false)
+Done
diff --git a/ext/standard/tests/array/array_walk_variation3.phpt b/ext/standard/tests/array/array_walk_variation3.phpt
new file mode 100644 (file)
index 0000000..ad26123
--- /dev/null
@@ -0,0 +1,123 @@
+--TEST--
+Test array_walk() function : usage variations - 'input' array with different values
+--FILE--
+<?php
+/* Prototype  : bool array_walk(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Testing array_walk() with following types of 'input' arrays:
+ *    integer, float, string, bool, null, empty & mixed
+*/
+
+// callback function
+/*
+ * Prototype : print_value(mixed $value, int $key, int $count)
+ * Parameters : $value - array entries(values)
+ *              $key - keys in given input array
+ *              $count - extra parameter used as an index
+ * Description : prints the array values with keys and count value
+ */
+function print_value($value, $key, $count)
+{
+  echo  $count." : ".$key." ".$value."\n";
+}
+
+echo "*** Testing array_walk() : 'input' array with different values***\n";
+
+// different arrays as input
+$input_values = array(
+  
+       // integer values
+/*1*/  array(1, 0, -10, 023, -041, 0x5A, 0X1F, -0x6E),
+  
+       // float value 
+       array(3.4, 0.8, -2.9, 6.25e2, 8.20E-3),
+
+       // string values
+       array('Mango', "Apple", 'Orange', "Lemon"),
+
+       // bool values
+/*4*/  array(true, false, TRUE, FALSE),
+
+       // null values
+       array(null, NULL),
+
+       // empty array
+       array(),
+
+       // binary array
+       array(b"binary"),
+      
+       // mixed array
+/*8*/  array(16, 8.345, "Fruits", true, null, FALSE, -98, 0.005, 'banana')
+);
+
+for($count = 0; $count < count($input_values); $count++) {
+  echo "\n-- Iteration ".($count + 1)." --\n";
+  var_dump( array_walk($input_values[$count], "print_value", $count+1));
+}  
+echo "Done"
+?>
+--EXPECTF--
+*** Testing array_walk() : 'input' array with different values***
+
+-- Iteration 1 --
+1 : 0 1
+1 : 1 0
+1 : 2 -10
+1 : 3 19
+1 : 4 -33
+1 : 5 90
+1 : 6 31
+1 : 7 -110
+bool(true)
+
+-- Iteration 2 --
+2 : 0 3.4
+2 : 1 0.8
+2 : 2 -2.9
+2 : 3 625
+2 : 4 0.0082
+bool(true)
+
+-- Iteration 3 --
+3 : 0 Mango
+3 : 1 Apple
+3 : 2 Orange
+3 : 3 Lemon
+bool(true)
+
+-- Iteration 4 --
+4 : 0 1
+4 : 1 
+4 : 2 1
+4 : 3 
+bool(true)
+
+-- Iteration 5 --
+5 : 0 
+5 : 1 
+bool(true)
+
+-- Iteration 6 --
+bool(true)
+
+-- Iteration 7 --
+7 : 0 binary
+bool(true)
+
+-- Iteration 8 --
+8 : 0 16
+8 : 1 8.345
+8 : 2 Fruits
+8 : 3 1
+8 : 4 
+8 : 5 
+8 : 6 -98
+8 : 7 0.005
+8 : 8 banana
+bool(true)
+Done
diff --git a/ext/standard/tests/array/array_walk_variation4.phpt b/ext/standard/tests/array/array_walk_variation4.phpt
new file mode 100644 (file)
index 0000000..868732d
--- /dev/null
@@ -0,0 +1,87 @@
+--TEST--
+Test array_walk() function : usage variations - 'input' array with subarray
+--FILE--
+<?php
+/* Prototype  : bool array_walk(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Testing array_walk() with an array having subarrays as elements 
+*/
+
+echo "*** Testing array_walk() : array with subarray ***\n";
+
+// callback function
+/* Prototype : callback(mixed $value, mixed $key)
+ * Parameters : $value - values in given 'input' array
+ *              $key - keys in given 'input' array
+ * Description : It prints the count of an array elements, passed as argument
+ */
+function callback($value, $key)
+{
+   // dump the arguments to check that they are passed
+   // with proper type
+   var_dump($key);  // key
+   var_dump($value); // value
+   echo "\n"; // new line to separate the output between each element
+}
+
+$input = array(
+  array(),
+  array(1),
+  array(1,2,3),
+  array("Mango", "Orange"),
+  array(array(1, 2, 3))
+);
+
+var_dump( array_walk( $input, "callback"));
+
+echo "Done"
+?>
+--EXPECTF--
+*** Testing array_walk() : array with subarray ***
+int(0)
+array(0) {
+}
+
+int(1)
+array(1) {
+  [0]=>
+  int(1)
+}
+
+int(2)
+array(3) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(2)
+  [2]=>
+  int(3)
+}
+
+int(3)
+array(2) {
+  [0]=>
+  string(5) "Mango"
+  [1]=>
+  string(6) "Orange"
+}
+
+int(4)
+array(1) {
+  [0]=>
+  array(3) {
+    [0]=>
+    int(1)
+    [1]=>
+    int(2)
+    [2]=>
+    int(3)
+  }
+}
+
+bool(true)
+Done
diff --git a/ext/standard/tests/array/array_walk_variation5.phpt b/ext/standard/tests/array/array_walk_variation5.phpt
new file mode 100644 (file)
index 0000000..f42e0f1
--- /dev/null
@@ -0,0 +1,64 @@
+--TEST--
+Test array_walk() function : usage variations - 'input' argument containing reference variables
+--FILE--
+<?php
+/* Prototype  : bool array_walk(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Testing array_walk() with an array having reference variables
+*/
+
+echo "*** Testing array_walk() : array with references ***\n";
+
+$value1 = 10;
+$value2 = -20;
+$value3 = &$value1;
+$value4 = 50;
+
+// 'input' array containing references to above variables
+$input = array(&$value1, &$value2, -35, &$value3, 0, &$value4);
+
+// callback function
+/* Prototype : callback(int $value, mixed $key)
+ * Parameters : $value - values in given input array
+ *              $key - keys in given input array
+ * Description : function checks for the value whether positive or negative and displays according to that
+ */
+function callback($value, $key)
+{
+   // dump the arguments to check that they are passed
+   // with proper type
+   var_dump($key);  // key
+   var_dump($value); // value
+   echo "\n"; // new line to separate the output between each element
+}
+
+var_dump( array_walk($input, "callback"));
+
+echo "Done"
+?>
+--EXPECTF--
+*** Testing array_walk() : array with references ***
+int(0)
+int(10)
+
+int(1)
+int(-20)
+
+int(2)
+int(-35)
+
+int(3)
+int(10)
+
+int(4)
+int(0)
+
+int(5)
+int(50)
+
+bool(true)
+Done
\ No newline at end of file
diff --git a/ext/standard/tests/array/array_walk_variation6.phpt b/ext/standard/tests/array/array_walk_variation6.phpt
new file mode 100644 (file)
index 0000000..c1f2323
--- /dev/null
@@ -0,0 +1,143 @@
+--TEST--
+Test array_walk() function : usage variations - 'input' argument as diff. associative arrays
+--FILE--
+<?php
+/* Prototype  : bool array_walk(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Passing 'input' argument as an associative array 
+ *    with Numeric & string keys
+*/
+
+echo "*** Testing array_walk() : 'input' as an associative array ***\n";
+
+// callback functions
+/* Prototype : for_numeric( int $value, int $key, int $user_data)
+ * Parameters : $value - value from key/value pair of the array 
+ *              $key - key from key/value pair of the array
+ *              $user_data - data to be added to 'value'
+ * Description : Function adds values with keys & user_data
+ */
+function for_numeric($value, $key, $user_data)
+{
+  // dump the input values to see if they are 
+  // passed with correct type
+  var_dump($key);
+  var_dump($value);
+  var_dump($user_data);
+  echo "\n"; // new line to separate the output between each element
+}
+
+/* Prototype : for_string( string $value, string $key)
+ * Parameters : $value - values in given input array
+ *              $key - keys in given input array
+ * Description : Function appends key to the value
+ */
+function for_string($value, $key)
+{
+  // dump the input values to see if they are 
+  // passed with correct type
+  var_dump($key);
+  var_dump($value);
+  echo "\n"; // new line to separate the output between each element
+}
+
+/* Prototype : for_mixed( mixed $value, mixed $key)
+ * Parameters : $value - values in given input array
+ *              $key - keys in given input array
+ * Description : Function displays each element of an array with keys
+ */
+function for_mixed($value, $key)
+{
+  // dump the input values to see if they are 
+  // passed with correct type
+  var_dump($key);
+  var_dump($value);
+  echo "\n"; // new line to separate the output between each element
+}
+
+// Numeric keys
+$input = array( 1 => 25, 5 => 12, 0 => -80, -2 => 100, 5 => 30);
+echo "-- Associative array with numeric keys --\n";
+var_dump( array_walk($input, "for_numeric", 10));
+
+// String keys
+$input = array( "a" => "Apple", 'b' => 'Bananna', "c" => "carrot", 'o' => "Orange");
+echo "-- Associative array with string keys --\n";
+var_dump( array_walk($input, "for_string"));
+
+// binary keys
+$input = array( b"a" => "Apple", b"b" => "Banana");
+echo "-- Associative array with binary keys --\n";
+var_dump( array_walk($input, "for_string"));
+
+// Mixed keys - numeric/string
+$input = array( 0 => 1, 1 => 2, "a" => "Apple", "b" => "Banana", 2 =>3);
+echo "-- Associative array with numeric/string keys --\n";
+var_dump( array_walk($input, "for_mixed"));
+
+echo "Done"
+?>
+--EXPECTF--
+*** Testing array_walk() : 'input' as an associative array ***
+-- Associative array with numeric keys --
+int(1)
+int(25)
+int(10)
+
+int(5)
+int(30)
+int(10)
+
+int(0)
+int(-80)
+int(10)
+
+int(-2)
+int(100)
+int(10)
+
+bool(true)
+-- Associative array with string keys --
+string(1) "a"
+string(5) "Apple"
+
+string(1) "b"
+string(7) "Bananna"
+
+string(1) "c"
+string(6) "carrot"
+
+string(1) "o"
+string(6) "Orange"
+
+bool(true)
+-- Associative array with binary keys --
+string(1) "a"
+string(5) "Apple"
+
+string(1) "b"
+string(6) "Banana"
+
+bool(true)
+-- Associative array with numeric/string keys --
+int(0)
+int(1)
+
+int(1)
+int(2)
+
+string(1) "a"
+string(5) "Apple"
+
+string(1) "b"
+string(6) "Banana"
+
+int(2)
+int(3)
+
+bool(true)
+Done
diff --git a/ext/standard/tests/array/array_walk_variation7.phpt b/ext/standard/tests/array/array_walk_variation7.phpt
new file mode 100644 (file)
index 0000000..da85958
--- /dev/null
@@ -0,0 +1,93 @@
+--TEST--
+Test array_walk() function : usage variations - anonymous callback function
+--FILE--
+<?php
+/* Prototype  : proto bool array_walk(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+/*
+* Passing anonymous(run-time) callback function with following variations:
+*   with one parameter
+*   two parameters
+*   three parameters
+*   extra parameters
+*   without parameters
+*/
+
+echo "*** Testing array_walk() : anonymous function as callback ***\n";
+
+$input = array(2, 5, 10, 0);
+
+echo "-- Anonymous function with one argument --\n";
+var_dump( array_walk($input, create_function('$value', 'var_dump($value); echo "\n";')));
+
+echo "-- Anonymous function with two arguments --\n";
+var_dump( array_walk($input, create_function('$value, $key', 'var_dump($key); var_dump($value); echo "\n";')));
+
+echo "-- Anonymous function with three arguments --\n";
+var_dump( array_walk($input, create_function('$value, $key, $user_data', 'var_dump($key); var_dump($value); var_dump($user_data); echo "\n";'), 10));
+
+echo "-- Anonymous function with one more argument --\n";
+var_dump( array_walk($input, create_function('$value, $key, $user_data', 'var_dump($key); var_dump($value); var_dump($user_data); echo "\n";'), 20, 30)); 
+
+echo "-- Anonymous function with null argument --\n";
+var_dump( array_walk( $input, create_function(null, 'echo "1\n";')));
+echo "Done"
+?>
+--EXPECTF--
+*** Testing array_walk() : anonymous function as callback ***
+-- Anonymous function with one argument --
+int(2)
+
+int(5)
+
+int(10)
+
+int(0)
+
+bool(true)
+-- Anonymous function with two arguments --
+int(0)
+int(2)
+
+int(1)
+int(5)
+
+int(2)
+int(10)
+
+int(3)
+int(0)
+
+bool(true)
+-- Anonymous function with three arguments --
+int(0)
+int(2)
+int(10)
+
+int(1)
+int(5)
+int(10)
+
+int(2)
+int(10)
+int(10)
+
+int(3)
+int(0)
+int(10)
+
+bool(true)
+-- Anonymous function with one more argument --
+
+Warning: array_walk() expects at most 3 parameters, 4 given in %s on line %d
+NULL
+-- Anonymous function with null argument --
+1
+1
+1
+1
+bool(true)
+Done
diff --git a/ext/standard/tests/array/array_walk_variation8.phpt b/ext/standard/tests/array/array_walk_variation8.phpt
new file mode 100644 (file)
index 0000000..2086394
--- /dev/null
@@ -0,0 +1,42 @@
+--TEST--
+Test array_walk() function : usage variations - buit-in function as callback
+--FILE--
+<?php
+/* Prototype  : bool array_walk(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Passing different buit-in functionns as callback function
+ *    pow function
+ *    min function
+ *    echo language construct
+*/
+
+echo "*** Testing array_walk() : built-in function as callback ***\n";
+
+$input = array(2 => 1, 65, 98, 100, 6 => -4);
+
+echo "-- With 'pow' built-in function --\n";
+var_dump( array_walk($input, 'pow'));
+
+echo "-- With 'min' built-in function --\n";
+var_dump( array_walk($input, "min"));
+
+echo "-- With 'echo' language construct --\n";
+var_dump( array_walk($input, "echo"));
+
+echo "Done"
+?>
+--EXPECTF--
+*** Testing array_walk() : built-in function as callback ***
+-- With 'pow' built-in function --
+bool(true)
+-- With 'min' built-in function --
+bool(true)
+-- With 'echo' language construct --
+
+Warning: array_walk(): Unable to call echo() - function does not exist in %s on line %d
+bool(true)
+Done
diff --git a/ext/standard/tests/array/array_walk_variation9.phpt b/ext/standard/tests/array/array_walk_variation9.phpt
new file mode 100644 (file)
index 0000000..42ae20d
--- /dev/null
@@ -0,0 +1,99 @@
+--TEST--
+Test array_walk() function : usage variations - different callback functions
+--FILE--
+<?php
+/* Prototype  : bool array_walk(array $input, string $funcname [, mixed $userdata])
+ * Description: Apply a user function to every member of an array 
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Passing different types of callback functions to array_walk()
+ *   without parameters
+ *   with less and more parameters
+*/
+
+echo "*** Testing array_walk() : callback function variation ***\n";
+
+$input = array('Apple', 'Banana', 'Mango', 'Orange');
+
+echo "-- callback function with both parameters --\n";
+function callback_two_parameter($value, $key)
+{
+   // dump the arguments to check that they are passed
+   // with proper type
+   var_dump($key);  // key
+   var_dump($value); // value
+   echo "\n"; // new line to separate the output between each element
+}
+var_dump( array_walk($input, 'callback_two_parameter'));
+
+echo "-- callback function with only one parameter --\n";
+function callback_one_parameter($value)
+{
+   // dump the arguments to check that they are passed
+   // with proper type
+   var_dump($value); // value
+   echo "\n"; // new line to separate the output between each element
+}
+var_dump( array_walk($input, 'callback_one_parameter'));
+
+echo "-- callback function without parameters --\n";
+function callback_no_parameter()
+{
+  echo "callback3() called\n";
+}
+var_dump( array_walk($input, 'callback_no_parameter'));
+
+echo "-- passing one more parameter to function with two parameters --\n";
+var_dump( array_walk($input, 'callback_two_parameter', 10)); 
+
+echo "Done"
+?>
+--EXPECTF--
+*** Testing array_walk() : callback function variation ***
+-- callback function with both parameters --
+int(0)
+string(5) "Apple"
+
+int(1)
+string(6) "Banana"
+
+int(2)
+string(5) "Mango"
+
+int(3)
+string(6) "Orange"
+
+bool(true)
+-- callback function with only one parameter --
+string(5) "Apple"
+
+string(6) "Banana"
+
+string(5) "Mango"
+
+string(6) "Orange"
+
+bool(true)
+-- callback function without parameters --
+callback3() called
+callback3() called
+callback3() called
+callback3() called
+bool(true)
+-- passing one more parameter to function with two parameters --
+int(0)
+string(5) "Apple"
+
+int(1)
+string(6) "Banana"
+
+int(2)
+string(5) "Mango"
+
+int(3)
+string(6) "Orange"
+
+bool(true)
+Done
\ No newline at end of file