]> granicus.if.org Git - php/commitdiff
New smaller testcases for array_map() function
authorRaghubansh Kumar <kraghuba@php.net>
Thu, 3 Jan 2008 09:35:11 +0000 (09:35 +0000)
committerRaghubansh Kumar <kraghuba@php.net>
Thu, 3 Jan 2008 09:35:11 +0000 (09:35 +0000)
21 files changed:
ext/standard/tests/array/array_map_basic.phpt [new file with mode: 0644]
ext/standard/tests/array/array_map_error.phpt [new file with mode: 0644]
ext/standard/tests/array/array_map_object1.phpt [new file with mode: 0644]
ext/standard/tests/array/array_map_object2.phpt [new file with mode: 0644]
ext/standard/tests/array/array_map_object3.phpt [new file with mode: 0644]
ext/standard/tests/array/array_map_variation10.phpt [new file with mode: 0644]
ext/standard/tests/array/array_map_variation11.phpt [new file with mode: 0644]
ext/standard/tests/array/array_map_variation12.phpt [new file with mode: 0644]
ext/standard/tests/array/array_map_variation13.phpt [new file with mode: 0644]
ext/standard/tests/array/array_map_variation14.phpt [new file with mode: 0644]
ext/standard/tests/array/array_map_variation15.phpt [new file with mode: 0644]
ext/standard/tests/array/array_map_variation16.phpt [new file with mode: 0644]
ext/standard/tests/array/array_map_variation17.phpt [new file with mode: 0644]
ext/standard/tests/array/array_map_variation18.phpt [new file with mode: 0644]
ext/standard/tests/array/array_map_variation3.phpt [new file with mode: 0644]
ext/standard/tests/array/array_map_variation4.phpt [new file with mode: 0644]
ext/standard/tests/array/array_map_variation5.phpt [new file with mode: 0644]
ext/standard/tests/array/array_map_variation6.phpt [new file with mode: 0644]
ext/standard/tests/array/array_map_variation7.phpt [new file with mode: 0644]
ext/standard/tests/array/array_map_variation8.phpt [new file with mode: 0644]
ext/standard/tests/array/array_map_variation9.phpt [new file with mode: 0644]

diff --git a/ext/standard/tests/array/array_map_basic.phpt b/ext/standard/tests/array/array_map_basic.phpt
new file mode 100644 (file)
index 0000000..5eab9c6
--- /dev/null
@@ -0,0 +1,98 @@
+--TEST--
+Test array_map() function : basic functionality
+--FILE--
+<?php
+/* Prototype  : array array_map  ( callback $callback  , array $arr1  [, array $...  ] )
+ * Description: Applies the callback to the elements of the given arrays
+ * Source code: ext/standard/array.c
+ */
+
+echo "*** Testing array_map() : basic functionality ***\n";
+
+function multiply($p, $q) {
+  return ($p * $q);
+}
+
+function square($p) {
+  return ($p * $p);
+}
+
+function concatenate($a, $b) {
+  return "$a = $b";
+}
+
+// integer array
+$arr1 = array(1, 2, 3);
+$arr2 = array(4, 5, 6);
+
+echo "-- With two integer array --\n";
+var_dump( array_map('multiply', $arr1, $arr2) );
+
+echo "-- With single integer array --\n";
+var_dump( array_map('square', $arr1) );
+
+// string array
+$arr1 = array("one", "two");
+$arr2 = array("single", "double");
+
+echo "-- With string array --\n";
+var_dump( array_map('concatenate', $arr1, $arr2) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_map() : basic functionality ***
+-- With two integer array --
+array(3) {
+  [0]=>
+  int(4)
+  [1]=>
+  int(10)
+  [2]=>
+  int(18)
+}
+-- With single integer array --
+array(3) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(4)
+  [2]=>
+  int(9)
+}
+-- With string array --
+array(2) {
+  [0]=>
+  string(12) "one = single"
+  [1]=>
+  string(12) "two = double"
+}
+Done
+--UEXPECTF--
+*** Testing array_map() : basic functionality ***
+-- With two integer array --
+array(3) {
+  [0]=>
+  int(4)
+  [1]=>
+  int(10)
+  [2]=>
+  int(18)
+}
+-- With single integer array --
+array(3) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(4)
+  [2]=>
+  int(9)
+}
+-- With string array --
+array(2) {
+  [0]=>
+  unicode(12) "one = single"
+  [1]=>
+  unicode(12) "two = double"
+}
+Done
\ No newline at end of file
diff --git a/ext/standard/tests/array/array_map_error.phpt b/ext/standard/tests/array/array_map_error.phpt
new file mode 100644 (file)
index 0000000..78924d3
--- /dev/null
@@ -0,0 +1,110 @@
+--TEST--
+Test array_map() function : error conditions
+--FILE--
+<?php
+/* Prototype  : array array_map  ( callback $callback  , array $arr1  [, array $...  ] )
+ * Description: Applies the callback to the elements of the given arrays
+ * Source code: ext/standard/array.c
+ */
+
+echo "*** Testing array_map() : error conditions ***\n";
+
+// Zero arguments
+echo "\n-- Testing array_map() function with Zero arguments --\n";
+var_dump( array_map() );
+
+// Testing array_map with one less than the expected number of arguments
+echo "\n-- Testing array_map() function with one less than expected no. of arguments --\n";
+function callback1() {
+  return 1;
+}
+var_dump( array_map('callback1') );
+
+echo "\n-- Testing array_map() function with less no. of arrays than callback function arguments --\n";
+$arr1 = array(1, 2);
+function callback2($p, $q) {
+  return $p * $q;
+}
+var_dump( array_map('callback2', $arr1) );
+
+echo "\n-- Testing array_map() function with more no. of arrays than callback function arguments --\n";
+$arr2 = array(3, 4);
+$arr3 = array(5, 6);
+var_dump( array_map('callback2', $arr1, $arr2, $arr3) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_map() : error conditions ***
+
+-- Testing array_map() function with Zero arguments --
+
+Warning: array_map() expects at least 2 parameters, 0 given in %s on line %d%d
+NULL
+
+-- Testing array_map() function with one less than expected no. of arguments --
+
+Warning: array_map() expects at least 2 parameters, 1 given in %s on line %d%d
+NULL
+
+-- Testing array_map() function with less no. of arrays than callback function arguments --
+
+Warning: Missing argument 2 for callback2() in %s on line %d%d
+
+Notice: Undefined variable: q in %s on line %d%d
+
+Warning: Missing argument 2 for callback2() in %s on line %d%d
+
+Notice: Undefined variable: q in %s on line %d%d
+array(2) {
+  [0]=>
+  int(0)
+  [1]=>
+  int(0)
+}
+
+-- Testing array_map() function with more no. of arrays than callback function arguments --
+array(2) {
+  [0]=>
+  int(3)
+  [1]=>
+  int(8)
+}
+Done
+--UEXPECTF--
+*** Testing array_map() : error conditions ***
+
+-- Testing array_map() function with Zero arguments --
+
+Warning: array_map() expects at least 2 parameters, 0 given in %s on line %d
+NULL
+
+-- Testing array_map() function with one less than expected no. of arguments --
+
+Warning: array_map() expects at least 2 parameters, 1 given in %s on line %d
+NULL
+
+-- Testing array_map() function with less no. of arrays than callback function arguments --
+
+Warning: Missing argument 2 for callback2() in %s on line %d
+
+Notice: Undefined variable: q in %s on line %d
+
+Warning: Missing argument 2 for callback2() in %s on line %d
+
+Notice: Undefined variable: q in %s on line %d
+array(2) {
+  [0]=>
+  int(0)
+  [1]=>
+  int(0)
+}
+
+-- Testing array_map() function with more no. of arrays than callback function arguments --
+array(2) {
+  [0]=>
+  int(3)
+  [1]=>
+  int(8)
+}
+Done
diff --git a/ext/standard/tests/array/array_map_object1.phpt b/ext/standard/tests/array/array_map_object1.phpt
new file mode 100644 (file)
index 0000000..f3bac6e
--- /dev/null
@@ -0,0 +1,219 @@
+--TEST--
+Test array_map() function : usage variations - object functionality
+--FILE--
+<?php
+/* Prototype  : array array_map  ( callback $callback  , array $arr1  [, array $...  ] )
+ * Description: Applies the callback to the elements of the given arrays
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Testing array_map() for object functionalities:
+ *   1) simple class with variable and method
+ *   2) class without members
+ *   3) class with only one method and no variable
+ *   4) abstract and child class
+ *   5) class with static and final members
+ *   6) interface and implemented class
+ */
+echo "*** Testing array_map() : object functionality ***\n";
+
+echo "-- simple class with public variable and method --\n";
+class SimpleClass
+{
+  public $var1 = 1;
+  public function square($n) {
+    return $n * $n;
+  }
+}
+var_dump( array_map(array('SimpleClass', 'square'), array(1, 2)) );
+
+echo "\n-- simple class with private variable and method --\n";
+class SimpleClassPri
+{
+  private $var1 = 10;
+  private function add($n) {
+    return $var + $n;
+  }
+}
+var_dump( array_map(array('SimpleClassPri', 'add'), array(1)) );
+
+echo "\n-- simple class with protected variable and method --\n";
+class SimpleClassPro
+{
+  protected $var1 = 5;
+  protected function mul($n) {
+    return $var1 * $n;
+  }
+}
+var_dump( array_map(array('SimpleClassPro', 'mul'), array(2)) );
+
+echo "\n-- class without members --";
+class EmptyClass
+{
+}
+var_dump( array_map(array('EmptyClass'), array(1, 2)) );
+
+echo "\n-- abstract class --";
+abstract class AbstractClass
+{
+  protected $var2 = 5;
+  abstract function emptyFunction();
+}
+
+// class deriving the above abstract class
+class ChildClass extends AbstractClass
+{
+  private $var3;
+  public function emptyFunction() {
+    echo "defined in child";
+  }
+}
+var_dump( array_map(array('ChildClass', 'emptyFunction'), array(1, 2)) );
+
+echo "\n-- class with final method --";
+class FinalClass
+{
+  private $var4;
+  final function finalMethod() {
+    echo "This function can't be overloaded";
+  }
+}
+var_dump( array_map(array('FinalClass', 'finalMethod'), array(1, 2)) );
+
+echo "\n-- class with static members --\n";
+class StaticClass
+{
+  static $var5 = 2;
+  public static function square($n) {
+    return ($n * $n);
+  }
+  private static function cube($n) {
+    return ($n * $n * $n);
+  }
+  protected static function retVal($n)  {
+    return array($n);
+  }
+}
+var_dump( array_map(array('StaticClass', 'square'), array(1, 2)) );
+var_dump( array_map(array('StaticClass', 'cube'), array(2)) );
+var_dump( array_map(array('StaticClass', 'retVal'), array(3, 4)) );
+
+echo "-- class implementing an interface --\n";
+interface myInterface
+{
+  public function toImplement();
+}
+class InterClass implements myInterface
+{
+  public static function square($n) {
+    return ($n * $n);
+  }
+  public function toImplement() {
+    return 1;
+  }
+}
+var_dump( array_map(array('InterClass', 'square'), array(1, 2)));
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_map() : object functionality ***
+-- simple class with public variable and method --
+
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d
+NULL
+
+-- simple class with private variable and method --
+
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d
+NULL
+
+-- simple class with protected variable and method --
+
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d
+NULL
+
+-- class without members --
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d
+NULL
+
+-- abstract class --
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d
+NULL
+
+-- class with final method --
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d
+NULL
+
+-- class with static members --
+array(2) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(4)
+}
+
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d
+NULL
+
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d
+NULL
+-- class implementing an interface --
+array(2) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(4)
+}
+Done
+--UEXPECTF--
+*** Testing array_map() : object functionality ***
+-- simple class with public variable and method --
+
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d
+NULL
+
+-- simple class with private variable and method --
+
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d
+NULL
+
+-- simple class with protected variable and method --
+
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d
+NULL
+
+-- class without members --
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d
+NULL
+
+-- abstract class --
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d
+NULL
+
+-- class with final method --
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d
+NULL
+
+-- class with static members --
+array(2) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(4)
+}
+
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d
+NULL
+
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d
+NULL
+-- class implementing an interface --
+array(2) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(4)
+}
+Done
diff --git a/ext/standard/tests/array/array_map_object2.phpt b/ext/standard/tests/array/array_map_object2.phpt
new file mode 100644 (file)
index 0000000..8f0e4b7
--- /dev/null
@@ -0,0 +1,57 @@
+--TEST--
+Test array_map() function : object functionality - with non-existent class and method 
+--FILE--
+<?php
+/* Prototype  : array array_map  ( callback $callback  , array $arr1  [, array $...  ] )
+ * Description: Applies the callback to the elements of the given arrays
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Testing array_map() for following object functionalities:
+ *   1) non-existent class
+ *   2) existent class and non-existent function
+ */
+echo "*** Testing array_map() :  with non-existent class and method ***\n";
+
+class SimpleClass
+{
+  public $var1 = 1;
+  public function square($n) {
+    return $n * $n;
+  }
+  public static function cube($n) {
+    return $n * $n * $n;
+  }
+}
+
+echo "-- with non-existent class --\n";
+var_dump( array_map(array('non-existent', 'square'), array(1, 2)) );
+
+echo "-- with existent class and non-existent method --\n";
+var_dump( array_map(array('SimpleClass', 'non-existent'), array(1, 2)) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_map() :  with non-existent class and method ***
+-- with non-existent class --
+
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d
+NULL
+-- with existent class and non-existent method --
+
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d
+NULL
+Done
+--UEXPECTF--
+*** Testing array_map() :  with non-existent class and method ***
+-- with non-existent class --
+
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d
+NULL
+-- with existent class and non-existent method --
+
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d
+NULL
+Done
diff --git a/ext/standard/tests/array/array_map_object3.phpt b/ext/standard/tests/array/array_map_object3.phpt
new file mode 100644 (file)
index 0000000..337b260
--- /dev/null
@@ -0,0 +1,121 @@
+--TEST--
+Test array_map() function : object functionality - class methods as callback function
+--FILE--
+<?php
+/* Prototype  : array array_map  ( callback $callback  , array $arr1  [, array $...  ] )
+ * Description: Applies the callback to the elements of the given arrays
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Testing array_map() for object functionality with following callback function variations:
+ *   1) child class method using parent object
+ *   2) parent class method using child object
+ *   3) child class method using parent class
+ *   4) parent class method using child class
+ */
+echo "*** Testing array_map() : class methods as callback function ***\n";
+
+$arr1 = array(1, 5, 7);
+
+class ParentClass
+{
+  public $var1 = 10;
+  public static function staticParent1($n) {
+    return $n;
+  }
+  private static function staticParent2($n) {
+    return $n;
+  }
+}
+
+class ChildClass extends ParentClass 
+{
+  var $parent_obj;
+  public function __construct ( ) {
+    $this->parent_obj = new ParentClass();
+  }
+  public $var2 = 5;
+  public static function staticChild($n) {
+    return $n;
+  }
+  public function nonstaticChild($n) {
+    return $n;
+  }
+}
+
+$childobj = new ChildClass();
+$parentobj = new ParentClass();
+
+echo "-- accessing parent method from child class --\n";
+var_dump( array_map(array('ChildClass', 'staticParent1'), $arr1) );
+
+echo "-- accessing child method from parent class --\n";
+var_dump( array_map(array('ParentClass', 'staticChild'), $arr1) );
+
+echo "-- accessing parent method using child class object --\n";
+var_dump( array_map(array($childobj, 'staticParent1'), $arr1) );
+
+echo "-- accessing child method using parent class object --\n";
+var_dump( array_map(array($parentobj, 'staticChild'), $arr1) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_map() : class methods as callback function ***
+-- accessing parent method from child class --
+array(3) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(5)
+  [2]=>
+  int(7)
+}
+-- accessing child method from parent class --
+
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d
+NULL
+-- accessing parent method using child class object --
+array(3) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(5)
+  [2]=>
+  int(7)
+}
+-- accessing child method using parent class object --
+
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d
+NULL
+Done
+--UEXPECTF--
+*** Testing array_map() : class methods as callback function ***
+-- accessing parent method from child class --
+array(3) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(5)
+  [2]=>
+  int(7)
+}
+-- accessing child method from parent class --
+
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d
+NULL
+-- accessing parent method using child class object --
+array(3) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(5)
+  [2]=>
+  int(7)
+}
+-- accessing child method using parent class object --
+
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d
+NULL
+Done
diff --git a/ext/standard/tests/array/array_map_variation10.phpt b/ext/standard/tests/array/array_map_variation10.phpt
new file mode 100644 (file)
index 0000000..8e4063a
--- /dev/null
@@ -0,0 +1,205 @@
+--TEST--
+Test array_map() function : usage variations - anonymous callback function
+--FILE--
+<?php
+/* Prototype  : array array_map  ( callback $callback  , array $arr1  [, array $...  ] )
+ * Description: Applies the callback to the elements of the given arrays 
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Test array_map() by passing anoymous callback function with following variations
+ */
+
+echo "*** Testing array_map() : anonymous callback function ***\n";
+
+$array1 = array(1, 2, 3);
+$array2 = array(3, 4, 5);
+
+echo "-- anonymous function with all parameters and body --\n";
+var_dump( array_map( create_function('$a, $b', 'return array($a, $b);'), $array1, $array2));
+
+echo "-- anonymous function with two parameters and passing one array --\n";
+var_dump( array_map( create_function('$a, $b', 'return array($a, $b);'), $array1));
+
+echo "-- anonymous function with NULL parameter --\n";
+var_dump( array_map( create_function(NULL, 'return NULL;'), $array1));
+
+echo "-- anonymous function with NULL body --\n";
+var_dump( array_map( create_function('$a', NULL), $array1));
+
+echo "-- passing NULL as 'arr1' --\n";
+var_dump( array_map( create_function('$a', 'return array($a);'), NULL));
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_map() : anonymous callback function ***
+-- anonymous function with all parameters and body --
+array(3) {
+  [0]=>
+  array(2) {
+    [0]=>
+    int(1)
+    [1]=>
+    int(3)
+  }
+  [1]=>
+  array(2) {
+    [0]=>
+    int(2)
+    [1]=>
+    int(4)
+  }
+  [2]=>
+  array(2) {
+    [0]=>
+    int(3)
+    [1]=>
+    int(5)
+  }
+}
+-- anonymous function with two parameters and passing one array --
+
+Warning: Missing argument 2 for __lambda_func() in %s(20) : runtime-created function on line %d
+
+Notice: Undefined variable: b in %s(20) : runtime-created function on line %d
+
+Warning: Missing argument 2 for __lambda_func() in %s(20) : runtime-created function on line %d
+
+Notice: Undefined variable: b in %s(20) : runtime-created function on line %d
+
+Warning: Missing argument 2 for __lambda_func() in %s(20) : runtime-created function on line %d
+
+Notice: Undefined variable: b in %s(20) : runtime-created function on line %d
+array(3) {
+  [0]=>
+  array(2) {
+    [0]=>
+    int(1)
+    [1]=>
+    NULL
+  }
+  [1]=>
+  array(2) {
+    [0]=>
+    int(2)
+    [1]=>
+    NULL
+  }
+  [2]=>
+  array(2) {
+    [0]=>
+    int(3)
+    [1]=>
+    NULL
+  }
+}
+-- anonymous function with NULL parameter --
+array(3) {
+  [0]=>
+  NULL
+  [1]=>
+  NULL
+  [2]=>
+  NULL
+}
+-- anonymous function with NULL body --
+array(3) {
+  [0]=>
+  NULL
+  [1]=>
+  NULL
+  [2]=>
+  NULL
+}
+-- passing NULL as 'arr1' --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+Done
+--UEXPECTF--
+*** Testing array_map() : anonymous callback function ***
+-- anonymous function with all parameters and body --
+array(3) {
+  [0]=>
+  array(2) {
+    [0]=>
+    int(1)
+    [1]=>
+    int(3)
+  }
+  [1]=>
+  array(2) {
+    [0]=>
+    int(2)
+    [1]=>
+    int(4)
+  }
+  [2]=>
+  array(2) {
+    [0]=>
+    int(3)
+    [1]=>
+    int(5)
+  }
+}
+-- anonymous function with two parameters and passing one array --
+
+Warning: Missing argument 2 for __lambda_func() in %s(20) : runtime-created function on line %d
+
+Notice: Undefined variable: b in %s(20) : runtime-created function on line %d
+
+Warning: Missing argument 2 for __lambda_func() in %s(20) : runtime-created function on line %d
+
+Notice: Undefined variable: b in %s(20) : runtime-created function on line %d
+
+Warning: Missing argument 2 for __lambda_func() in %s(20) : runtime-created function on line %d
+
+Notice: Undefined variable: b in %s(20) : runtime-created function on line %d
+array(3) {
+  [0]=>
+  array(2) {
+    [0]=>
+    int(1)
+    [1]=>
+    NULL
+  }
+  [1]=>
+  array(2) {
+    [0]=>
+    int(2)
+    [1]=>
+    NULL
+  }
+  [2]=>
+  array(2) {
+    [0]=>
+    int(3)
+    [1]=>
+    NULL
+  }
+}
+-- anonymous function with NULL parameter --
+array(3) {
+  [0]=>
+  NULL
+  [1]=>
+  NULL
+  [2]=>
+  NULL
+}
+-- anonymous function with NULL body --
+array(3) {
+  [0]=>
+  NULL
+  [1]=>
+  NULL
+  [2]=>
+  NULL
+}
+-- passing NULL as 'arr1' --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+Done
diff --git a/ext/standard/tests/array/array_map_variation11.phpt b/ext/standard/tests/array/array_map_variation11.phpt
new file mode 100644 (file)
index 0000000..34d7054
--- /dev/null
@@ -0,0 +1,76 @@
+--TEST--
+Test array_map() function : usage variations - with recursive callback
+--FILE--
+<?php
+/* Prototype  : array array_map  ( callback $callback  , array $arr1  [, array $...  ] )
+ * Description: Applies the callback to the elements of the given arrays 
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Test array_map() by passing subarrays and recursive callback function
+ */
+
+echo "*** Testing array_map() : recursive callback function ***\n";
+
+// callback function
+function square_recur_single_array($var) {
+   if (is_array($var))
+     return array_map('square_recur_single_array', $var);
+   return $var * $var;
+}
+
+$array1 = array(1, array(2, 3, array(5)), array(4));
+
+var_dump( array_map('square_recur_single_array', $array1));
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_map() : recursive callback function ***
+array(3) {
+  [0]=>
+  int(1)
+  [1]=>
+  array(3) {
+    [0]=>
+    int(4)
+    [1]=>
+    int(9)
+    [2]=>
+    array(1) {
+      [0]=>
+      int(25)
+    }
+  }
+  [2]=>
+  array(1) {
+    [0]=>
+    int(16)
+  }
+}
+Done
+--UEXPECTF--
+*** Testing array_map() : recursive callback function ***
+array(3) {
+  [0]=>
+  int(1)
+  [1]=>
+  array(3) {
+    [0]=>
+    int(4)
+    [1]=>
+    int(9)
+    [2]=>
+    array(1) {
+      [0]=>
+      int(25)
+    }
+  }
+  [2]=>
+  array(1) {
+    [0]=>
+    int(16)
+  }
+}
+Done
diff --git a/ext/standard/tests/array/array_map_variation12.phpt b/ext/standard/tests/array/array_map_variation12.phpt
new file mode 100644 (file)
index 0000000..fbd4c8e
--- /dev/null
@@ -0,0 +1,91 @@
+--TEST--
+Test array_map() function : usage variations - built-in function as callback
+--FILE--
+<?php
+/* Prototype  : array array_map  ( callback $callback  , array $arr1  [, array $...  ] )
+ * Description: Applies the callback to the elements of the given arrays 
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Test array_map() by passing buit-in function as callback function
+ */
+
+echo "*** Testing array_map() : built-in function ***\n";
+
+$array1 = array(1, 2, 3);
+$array2 = array(3, 4, 5);
+
+echo "-- with built-in function 'pow' and two parameters --\n";
+var_dump( array_map('pow', $array1, $array2));
+
+echo "-- with built-in function 'pow' and one parameter --\n";
+var_dump( array_map('pow', $array1));
+
+echo "-- with language construct --\n";
+var_dump( array_map('echo', $array1));
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_map() : built-in function ***
+-- with built-in function 'pow' and two parameters --
+array(3) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(16)
+  [2]=>
+  int(243)
+}
+-- with built-in function 'pow' and one parameter --
+
+Warning: pow() expects exactly 2 parameters, 1 given in %s on line %d%d
+
+Warning: pow() expects exactly 2 parameters, 1 given in %s on line %d%d
+
+Warning: pow() expects exactly 2 parameters, 1 given in %s on line %d%d
+array(3) {
+  [0]=>
+  NULL
+  [1]=>
+  NULL
+  [2]=>
+  NULL
+}
+-- with language construct --
+
+Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d
+NULL
+Done
+--UEXPECTF--
+*** Testing array_map() : built-in function ***
+-- with built-in function 'pow' and two parameters --
+array(3) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(16)
+  [2]=>
+  int(243)
+}
+-- with built-in function 'pow' and one parameter --
+
+Warning: pow() expects exactly 2 parameters, 1 given in %s on line %d
+
+Warning: pow() expects exactly 2 parameters, 1 given in %s on line %d
+
+Warning: pow() expects exactly 2 parameters, 1 given in %s on line %d
+array(3) {
+  [0]=>
+  NULL
+  [1]=>
+  NULL
+  [2]=>
+  NULL
+}
+-- with language construct --
+
+Warning: array_map() expects parameter 1 to be valid callback, Unicode string given in %s on line %d
+NULL
+Done
diff --git a/ext/standard/tests/array/array_map_variation13.phpt b/ext/standard/tests/array/array_map_variation13.phpt
new file mode 100644 (file)
index 0000000..002c18e
--- /dev/null
@@ -0,0 +1,158 @@
+--TEST--
+Test array_map() function : usage variations - callback function with different return types
+--FILE--
+<?php
+/* Prototype  : array array_map  ( callback $callback  , array $arr1  [, array $...  ] )
+ * Description: Applies the callback to the elements of the given arrays 
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Test array_map() by passing different callback function returning:
+ *   int, string, bool, null values
+ */
+
+echo "*** Testing array_map() : callback with diff return value ***\n";
+
+$array1 = array(1, 2, 3);
+$array2 = array(3, 4, 5);
+
+echo "-- with integer return value --\n";
+function callback_int($a, $b)
+{
+  return $a + $b;
+}
+var_dump( array_map('callback_int', $array1, $array2));
+
+echo "-- with string return value --\n";
+function callback_string($a, $b)
+{
+  return "$a"."$b";
+}
+var_dump( array_map('callback_string', $array1, $array2));
+
+echo "-- with bool return value --\n";
+function callback_bool($a, $b)
+{
+  return TRUE;
+}
+var_dump( array_map('callback_bool', $array1, $array2));
+
+echo "-- with null return value --\n";
+function callback_null($array1)
+{
+  return NULL;
+}
+var_dump( array_map('callback_null', $array1));
+
+echo "-- with no return value --\n";
+function callback_without_ret($arr1)
+{
+  echo "callback_without_ret called\n";
+}
+var_dump( array_map('callback_without_ret', $array1));
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_map() : callback with diff return value ***
+-- with integer return value --
+array(3) {
+  [0]=>
+  int(4)
+  [1]=>
+  int(6)
+  [2]=>
+  int(8)
+}
+-- with string return value --
+array(3) {
+  [0]=>
+  string(2) "13"
+  [1]=>
+  string(2) "24"
+  [2]=>
+  string(2) "35"
+}
+-- with bool return value --
+array(3) {
+  [0]=>
+  bool(true)
+  [1]=>
+  bool(true)
+  [2]=>
+  bool(true)
+}
+-- with null return value --
+array(3) {
+  [0]=>
+  NULL
+  [1]=>
+  NULL
+  [2]=>
+  NULL
+}
+-- with no return value --
+callback_without_ret called
+callback_without_ret called
+callback_without_ret called
+array(3) {
+  [0]=>
+  NULL
+  [1]=>
+  NULL
+  [2]=>
+  NULL
+}
+Done
+--UEXPECTF--
+*** Testing array_map() : callback with diff return value ***
+-- with integer return value --
+array(3) {
+  [0]=>
+  int(4)
+  [1]=>
+  int(6)
+  [2]=>
+  int(8)
+}
+-- with string return value --
+array(3) {
+  [0]=>
+  unicode(2) "13"
+  [1]=>
+  unicode(2) "24"
+  [2]=>
+  unicode(2) "35"
+}
+-- with bool return value --
+array(3) {
+  [0]=>
+  bool(true)
+  [1]=>
+  bool(true)
+  [2]=>
+  bool(true)
+}
+-- with null return value --
+array(3) {
+  [0]=>
+  NULL
+  [1]=>
+  NULL
+  [2]=>
+  NULL
+}
+-- with no return value --
+callback_without_ret called
+callback_without_ret called
+callback_without_ret called
+array(3) {
+  [0]=>
+  NULL
+  [1]=>
+  NULL
+  [2]=>
+  NULL
+}
+Done
diff --git a/ext/standard/tests/array/array_map_variation14.phpt b/ext/standard/tests/array/array_map_variation14.phpt
new file mode 100644 (file)
index 0000000..7db4c97
--- /dev/null
@@ -0,0 +1,205 @@
+--TEST--
+Test array_map() function : usage variations - null value for 'callback' argument
+--FILE--
+<?php
+/* Prototype  : array array_map  ( callback $callback  , array $arr1  [, array $...  ] )
+ * Description: Applies the callback to the elements of the given arrays
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Test array_map() by passing null values for $callback argument and testing whether shortest
+ * array will be extended with empty elements
+ */
+
+echo "*** Testing array_map() : null value for 'callback' argument ***\n";
+
+// arrays to be passed as arguments
+$arr1 = array(1, 2);
+$arr2 = array("one", "two");
+$arr3 = array(1.1, 2.2);
+
+// get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+/* calling array_map() with null callback */
+
+echo "-- with null --\n";
+var_dump( array_map(null, $arr1, $arr2, $arr3) );
+var_dump( array_map(NULL, $arr1, $arr2, $arr3) );
+
+echo "-- with unset variable --\n";
+var_dump( array_map(@$unset_var, $arr1, $arr2, $arr3) );
+
+echo "-- with undefined variable --\n";
+var_dump( array_map(@$undefined_var, $arr1) );
+
+echo "-- with empty string --\n";
+var_dump( array_map("", $arr1, $arr2) );
+
+echo "-- with empty array --\n";
+var_dump( array_map(array(), $arr1, $arr2) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_map() : null value for 'callback' argument ***
+-- with null --
+array(2) {
+  [0]=>
+  array(3) {
+    [0]=>
+    int(1)
+    [1]=>
+    string(3) "one"
+    [2]=>
+    float(1.1)
+  }
+  [1]=>
+  array(3) {
+    [0]=>
+    int(2)
+    [1]=>
+    string(3) "two"
+    [2]=>
+    float(2.2)
+  }
+}
+array(2) {
+  [0]=>
+  array(3) {
+    [0]=>
+    int(1)
+    [1]=>
+    string(3) "one"
+    [2]=>
+    float(1.1)
+  }
+  [1]=>
+  array(3) {
+    [0]=>
+    int(2)
+    [1]=>
+    string(3) "two"
+    [2]=>
+    float(2.2)
+  }
+}
+-- with unset variable --
+array(2) {
+  [0]=>
+  array(3) {
+    [0]=>
+    int(1)
+    [1]=>
+    string(3) "one"
+    [2]=>
+    float(1.1)
+  }
+  [1]=>
+  array(3) {
+    [0]=>
+    int(2)
+    [1]=>
+    string(3) "two"
+    [2]=>
+    float(2.2)
+  }
+}
+-- with undefined variable --
+array(2) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(2)
+}
+-- with empty string --
+
+Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d
+NULL
+-- with empty array --
+
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d
+NULL
+Done
+--UEXPECTF--
+*** Testing array_map() : null value for 'callback' argument ***
+-- with null --
+array(2) {
+  [0]=>
+  array(3) {
+    [0]=>
+    int(1)
+    [1]=>
+    unicode(3) "one"
+    [2]=>
+    float(1.1)
+  }
+  [1]=>
+  array(3) {
+    [0]=>
+    int(2)
+    [1]=>
+    unicode(3) "two"
+    [2]=>
+    float(2.2)
+  }
+}
+array(2) {
+  [0]=>
+  array(3) {
+    [0]=>
+    int(1)
+    [1]=>
+    unicode(3) "one"
+    [2]=>
+    float(1.1)
+  }
+  [1]=>
+  array(3) {
+    [0]=>
+    int(2)
+    [1]=>
+    unicode(3) "two"
+    [2]=>
+    float(2.2)
+  }
+}
+-- with unset variable --
+array(2) {
+  [0]=>
+  array(3) {
+    [0]=>
+    int(1)
+    [1]=>
+    unicode(3) "one"
+    [2]=>
+    float(1.1)
+  }
+  [1]=>
+  array(3) {
+    [0]=>
+    int(2)
+    [1]=>
+    unicode(3) "two"
+    [2]=>
+    float(2.2)
+  }
+}
+-- with undefined variable --
+array(2) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(2)
+}
+-- with empty string --
+
+Warning: array_map() expects parameter 1 to be valid callback, Unicode string given in %s on line %d
+NULL
+-- with empty array --
+
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d
+NULL
+Done
diff --git a/ext/standard/tests/array/array_map_variation15.phpt b/ext/standard/tests/array/array_map_variation15.phpt
new file mode 100644 (file)
index 0000000..869645a
--- /dev/null
@@ -0,0 +1,36 @@
+--TEST--
+Test array_map() function : usage variations - non existent 'callback' function
+--FILE--
+<?php
+/* Prototype  : array array_map  ( callback $callback  , array $arr1  [, array $...  ] )
+ * Description: Applies the callback to the elements of the given arrays
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Test array_map() by passing non existent function for $callback argument
+ */
+
+echo "*** Testing array_map() : non existent 'callback' function ***\n";
+
+// arrays to be passed as arguments
+$arr1 = array(1, 2);
+$arr2 = array("one", "two");
+$arr3 = array(1.1, 2.2);
+
+var_dump( array_map('non_existent', $arr1, $arr2, $arr3) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_map() : non existent 'callback' function ***
+
+Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d
+NULL
+Done
+--UEXPECTF--
+*** Testing array_map() : non existent 'callback' function ***
+
+Warning: array_map() expects parameter 1 to be valid callback, Unicode string given in %s on line %d
+NULL
+Done
diff --git a/ext/standard/tests/array/array_map_variation16.phpt b/ext/standard/tests/array/array_map_variation16.phpt
new file mode 100644 (file)
index 0000000..200a015
--- /dev/null
@@ -0,0 +1,108 @@
+--TEST--
+Test array_map() function : usage variations - failing built-in functions & language constructs
+--FILE--
+<?php
+/* Prototype  : array array_map  ( callback $callback  , array $arr1  [, array $...  ] )
+ * Description: Applies the callback to the elements of the given arrays
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Test array_map() by passing non-permmited built-in functions and language constructs i.e.
+ *   echo(), array(), empty(), eval(), exit(), isset(), list(), print()
+ */
+
+echo "*** Testing array_map() : non-permmited built-in functions ***\n";
+
+// array to be passed as arguments
+$arr1 = array(1, 2);
+
+// built-in functions & language constructs
+$callback_names = array(
+/*1*/  'echo',
+       'array',
+       'empty',
+/*4*/  'eval',
+       'exit',
+       'isset',
+       'list',
+/*8*/  'print'
+);
+for($count = 0; $count < count($callback_names); $count++)
+{
+  echo "-- Iteration ".($count + 1)." --\n";
+  var_dump( array_map($callback_names[$count], $arr1) );
+}
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_map() : non-permmited built-in functions ***
+-- Iteration 1 --
+
+Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d
+NULL
+-- Iteration 2 --
+
+Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d
+NULL
+-- Iteration 3 --
+
+Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d
+NULL
+-- Iteration 4 --
+
+Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d
+NULL
+-- Iteration 5 --
+
+Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d
+NULL
+-- Iteration 6 --
+
+Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d
+NULL
+-- Iteration 7 --
+
+Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d
+NULL
+-- Iteration 8 --
+
+Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d
+NULL
+Done
+--UEXPECTF--
+*** Testing array_map() : non-permmited built-in functions ***
+-- Iteration 1 --
+
+Warning: array_map() expects parameter 1 to be valid callback, Unicode string given in %s on line %d
+NULL
+-- Iteration 2 --
+
+Warning: array_map() expects parameter 1 to be valid callback, Unicode string given in %s on line %d
+NULL
+-- Iteration 3 --
+
+Warning: array_map() expects parameter 1 to be valid callback, Unicode string given in %s on line %d
+NULL
+-- Iteration 4 --
+
+Warning: array_map() expects parameter 1 to be valid callback, Unicode string given in %s on line %d
+NULL
+-- Iteration 5 --
+
+Warning: array_map() expects parameter 1 to be valid callback, Unicode string given in %s on line %d
+NULL
+-- Iteration 6 --
+
+Warning: array_map() expects parameter 1 to be valid callback, Unicode string given in %s on line %d
+NULL
+-- Iteration 7 --
+
+Warning: array_map() expects parameter 1 to be valid callback, Unicode string given in %s on line %d
+NULL
+-- Iteration 8 --
+
+Warning: array_map() expects parameter 1 to be valid callback, Unicode string given in %s on line %d
+NULL
+Done
diff --git a/ext/standard/tests/array/array_map_variation17.phpt b/ext/standard/tests/array/array_map_variation17.phpt
new file mode 100644 (file)
index 0000000..99c9167
--- /dev/null
@@ -0,0 +1,241 @@
+--TEST--
+Test array_map() function : usage variations - unexpected values for 'callback' argument
+--FILE--
+<?php
+/* Prototype  : array array_map  ( callback $callback  , array $arr1  [, array $...  ] )
+ * Description: Applies the callback to the elements of the given arrays 
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Test array_map() by passing different scalar/nonscalar values in place of $callback
+ */
+
+echo "*** Testing array_map() : unexpected values for 'callback' argument ***\n";
+
+$arr1 = array(1, 2, 3);
+
+// get a class
+class classA
+{
+  public function __toString() {
+    return "Class A object";
+  }
+}
+
+// get a resource variable
+$fp = fopen(__FILE__, "r");
+
+// unexpected values to be passed to $input argument
+$unexpected_callbacks = array(
+
+       // int data
+/*1*/  0,
+       1,
+       12345,
+       -2345,
+
+       // float data
+/*5*/  10.5,
+       -10.5,
+       12.3456789000e10,
+       12.3456789000E-10,
+       .5,
+
+       // boolean data
+/*10*/ true,
+       false,
+       TRUE,
+       FALSE,
+       
+       // empty data
+/*14*/ "",
+       '',
+
+       // array data
+/*16*/ array(),
+       array(1, 2),
+       array(1, array(2)),
+
+       // object data
+/*19*/ new classA(),
+
+       // resource variable
+/*20*/ $fp
+);
+
+// loop through each element of $inputs to check the behavior of array_map
+for($count = 0; $count < count($unexpected_callbacks); $count++) {
+  echo "\n-- Iteration ".($count + 1)." --";
+  var_dump( array_map($unexpected_callbacks[$count], $arr1));
+};
+
+fclose($fp);
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_map() : unexpected values for 'callback' argument ***
+
+-- Iteration 1 --
+Warning: array_map() expects parameter 1 to be valid callback, integer given in %s on line %d%d
+NULL
+
+-- Iteration 2 --
+Warning: array_map() expects parameter 1 to be valid callback, integer given in %s on line %d%d
+NULL
+
+-- Iteration 3 --
+Warning: array_map() expects parameter 1 to be valid callback, integer given in %s on line %d%d
+NULL
+
+-- Iteration 4 --
+Warning: array_map() expects parameter 1 to be valid callback, integer given in %s on line %d%d
+NULL
+
+-- Iteration 5 --
+Warning: array_map() expects parameter 1 to be valid callback, double given in %s on line %d%d
+NULL
+
+-- Iteration 6 --
+Warning: array_map() expects parameter 1 to be valid callback, double given in %s on line %d%d
+NULL
+
+-- Iteration 7 --
+Warning: array_map() expects parameter 1 to be valid callback, double given in %s on line %d%d
+NULL
+
+-- Iteration 8 --
+Warning: array_map() expects parameter 1 to be valid callback, double given in %s on line %d%d
+NULL
+
+-- Iteration 9 --
+Warning: array_map() expects parameter 1 to be valid callback, double given in %s on line %d%d
+NULL
+
+-- Iteration 10 --
+Warning: array_map() expects parameter 1 to be valid callback, boolean given in %s on line %d%d
+NULL
+
+-- Iteration 11 --
+Warning: array_map() expects parameter 1 to be valid callback, boolean given in %s on line %d%d
+NULL
+
+-- Iteration 12 --
+Warning: array_map() expects parameter 1 to be valid callback, boolean given in %s on line %d%d
+NULL
+
+-- Iteration 13 --
+Warning: array_map() expects parameter 1 to be valid callback, boolean given in %s on line %d%d
+NULL
+
+-- Iteration 14 --
+Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d
+NULL
+
+-- Iteration 15 --
+Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d
+NULL
+
+-- Iteration 16 --
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d
+NULL
+
+-- Iteration 17 --
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d
+NULL
+
+-- Iteration 18 --
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d
+NULL
+
+-- Iteration 19 --
+Warning: array_map() expects parameter 1 to be valid callback, object given in %s on line %d%d
+NULL
+
+-- Iteration 20 --
+Warning: array_map() expects parameter 1 to be valid callback, resource given in %s on line %d%d
+NULL
+Done
+--UEXPECTF--
+*** Testing array_map() : unexpected values for 'callback' argument ***
+
+-- Iteration 1 --
+Warning: array_map() expects parameter 1 to be valid callback, integer given in %s on line %d
+NULL
+
+-- Iteration 2 --
+Warning: array_map() expects parameter 1 to be valid callback, integer given in %s on line %d
+NULL
+
+-- Iteration 3 --
+Warning: array_map() expects parameter 1 to be valid callback, integer given in %s on line %d
+NULL
+
+-- Iteration 4 --
+Warning: array_map() expects parameter 1 to be valid callback, integer given in %s on line %d
+NULL
+
+-- Iteration 5 --
+Warning: array_map() expects parameter 1 to be valid callback, double given in %s on line %d
+NULL
+
+-- Iteration 6 --
+Warning: array_map() expects parameter 1 to be valid callback, double given in %s on line %d
+NULL
+
+-- Iteration 7 --
+Warning: array_map() expects parameter 1 to be valid callback, double given in %s on line %d
+NULL
+
+-- Iteration 8 --
+Warning: array_map() expects parameter 1 to be valid callback, double given in %s on line %d
+NULL
+
+-- Iteration 9 --
+Warning: array_map() expects parameter 1 to be valid callback, double given in %s on line %d
+NULL
+
+-- Iteration 10 --
+Warning: array_map() expects parameter 1 to be valid callback, boolean given in %s on line %d
+NULL
+
+-- Iteration 11 --
+Warning: array_map() expects parameter 1 to be valid callback, boolean given in %s on line %d
+NULL
+
+-- Iteration 12 --
+Warning: array_map() expects parameter 1 to be valid callback, boolean given in %s on line %d
+NULL
+
+-- Iteration 13 --
+Warning: array_map() expects parameter 1 to be valid callback, boolean given in %s on line %d
+NULL
+
+-- Iteration 14 --
+Warning: array_map() expects parameter 1 to be valid callback, Unicode string given in %s on line %d
+NULL
+
+-- Iteration 15 --
+Warning: array_map() expects parameter 1 to be valid callback, Unicode string given in %s on line %d
+NULL
+
+-- Iteration 16 --
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d
+NULL
+
+-- Iteration 17 --
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d
+NULL
+
+-- Iteration 18 --
+Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d
+NULL
+
+-- Iteration 19 --
+Warning: array_map() expects parameter 1 to be valid callback, object given in %s on line %d
+NULL
+
+-- Iteration 20 --
+Warning: array_map() expects parameter 1 to be valid callback, resource given in %s on line %d
+NULL
+Done
diff --git a/ext/standard/tests/array/array_map_variation18.phpt b/ext/standard/tests/array/array_map_variation18.phpt
new file mode 100644 (file)
index 0000000..c369c3c
--- /dev/null
@@ -0,0 +1,308 @@
+--TEST--
+Test array_map() function : usage variations - unexpected values for 'arr1' argument
+--FILE--
+<?php
+/* Prototype  : array array_map  ( callback $callback  , array $arr1  [, array $...  ] )
+ * Description: Applies the callback to the elements of the given arrays
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Test array_map() by passing non array values in place of $arr1
+ */
+
+echo "*** Testing array_map() : unexpected values for 'arr1' ***\n";
+
+function callback($a)
+{
+  return $a;
+}
+
+//get an unset array variable
+$unset_var1 = array(1, 2);
+unset ($unset_var1);
+
+// get an unset variable
+$unset_var2 = 10;
+unset ($unset_var2);
+
+// get a class
+class classA
+{
+  public function __toString() {
+    return "Class A object";
+  }
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// get a resource variable
+$fp = fopen(__FILE__, "r");
+
+// different scalar/non-scalar values for array input
+$unexpected_inputs = array(
+
+       // int data
+/*1*/  0,
+       1,
+       12345,
+       -2345,
+
+       // float data
+/*5*/  10.5,
+       -10.5,
+       12.3456789000e10,
+       12.3456789000E-10,
+       .5,
+
+       // null data
+/*10*/ NULL,
+       null,
+
+       // boolean data
+/*12*/ true,
+       false,
+       TRUE,
+       FALSE,
+       
+       // empty data
+/*16*/ "",
+       '',
+
+       // string data
+/*18*/ "string",
+       'string',
+       $heredoc,
+       
+       // object data
+/*21*/ new classA(),
+
+       // undefined data
+/*22*/ @$undefined_var,
+
+       // unset data
+/*23*/ @$unset_var1,
+       @$unset_var2,
+
+       // resource variable
+/*25*/ $fp
+);
+
+// loop through each element of $unexpected_inputs to check the behavior of array_map
+for($count = 0; $count < count($unexpected_inputs); $count++) {
+  echo "-- Iteration ".($count + 1)." --\n";
+  var_dump( array_map('callback', $unexpected_inputs[$count]));
+};
+
+fclose($fp);
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_map() : unexpected values for 'arr1' ***
+-- Iteration 1 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 2 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 3 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 4 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 5 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 6 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 7 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 8 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 9 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 10 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 11 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 12 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 13 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 14 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 15 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 16 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 17 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 18 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 19 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 20 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 21 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 22 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 23 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 24 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+-- Iteration 25 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d%d
+NULL
+Done
+--UEXPECTF--
+*** Testing array_map() : unexpected values for 'arr1' ***
+-- Iteration 1 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 2 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 3 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 4 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 5 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 6 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 7 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 8 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 9 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 10 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 11 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 12 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 13 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 14 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 15 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 16 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 17 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 18 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 19 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 20 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 21 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 22 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 23 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 24 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+-- Iteration 25 --
+
+Warning: array_map(): Argument #2 should be an array in %s on line %d
+NULL
+Done
diff --git a/ext/standard/tests/array/array_map_variation3.phpt b/ext/standard/tests/array/array_map_variation3.phpt
new file mode 100644 (file)
index 0000000..eadf4e6
--- /dev/null
@@ -0,0 +1,396 @@
+--TEST--
+Test array_map() function : usage variations - different arrays for 'arr1' argument
+--FILE--
+<?php
+/* Prototype  : array array_map  ( callback $callback  , array $arr1  [, array $...  ] )
+ * Description: Applies the callback to the elements of the given arrays
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Test array_map() by passing different arrays for $arr1 argument
+ */
+
+echo "*** Testing array_map() : different arrays for 'arr1' argument ***\n";
+
+function callback($a)
+{
+  return ($a);
+}
+
+// different arrays
+$arrays = array (
+/*1*/  array(1, 2), // array with default keys and numeric values
+       array(1.1, 2.2), // array with default keys & float values
+       array( array(2), array(1)), // sub arrays
+       array(false,true), // array with default keys and boolean values
+       array(), // empty array
+       array(NULL), // array with NULL
+       array("a","aaaa","b","bbbb","c","ccccc"),
+
+       // associative arrays
+/*8*/  array(1 => "one", 2 => "two", 3 => "three"),  // explicit numeric keys, string values
+       array("one" => 1, "two" => 2, "three" => 3 ),  // string keys & numeric values
+       array( 1 => 10, 2 => 20, 4 => 40, 3 => 30),  // explicit numeric keys and numeric values
+       array( "one" => "ten", "two" => "twenty", "three" => "thirty"),  // string key/value
+       array("one" => 1, 2 => "two", 4 => "four"),  //mixed
+
+       // associative array, containing null/empty/boolean values as key/value
+/*13*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null),
+       array(true => "true", false => "false", "false" => false, "true" => true),
+       array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''),
+       array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true),
+       array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6),
+
+       // array with repetative keys
+/*18*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3)
+);
+
+// loop through the various elements of $arrays to test array_map()
+$iterator = 1;
+foreach($arrays as $arr1) {
+  echo "-- Iteration $iterator --\n";
+  var_dump( array_map('callback', $arr1) );
+  $iterator++;
+}
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_map() : different arrays for 'arr1' argument ***
+-- Iteration 1 --
+array(2) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(2)
+}
+-- Iteration 2 --
+array(2) {
+  [0]=>
+  float(1.1)
+  [1]=>
+  float(2.2)
+}
+-- Iteration 3 --
+array(2) {
+  [0]=>
+  array(1) {
+    [0]=>
+    int(2)
+  }
+  [1]=>
+  array(1) {
+    [0]=>
+    int(1)
+  }
+}
+-- Iteration 4 --
+array(2) {
+  [0]=>
+  bool(false)
+  [1]=>
+  bool(true)
+}
+-- Iteration 5 --
+array(0) {
+}
+-- Iteration 6 --
+array(1) {
+  [0]=>
+  NULL
+}
+-- Iteration 7 --
+array(6) {
+  [0]=>
+  string(1) "a"
+  [1]=>
+  string(4) "aaaa"
+  [2]=>
+  string(1) "b"
+  [3]=>
+  string(4) "bbbb"
+  [4]=>
+  string(1) "c"
+  [5]=>
+  string(5) "ccccc"
+}
+-- Iteration 8 --
+array(3) {
+  [1]=>
+  string(3) "one"
+  [2]=>
+  string(3) "two"
+  [3]=>
+  string(5) "three"
+}
+-- Iteration 9 --
+array(3) {
+  ["one"]=>
+  int(1)
+  ["two"]=>
+  int(2)
+  ["three"]=>
+  int(3)
+}
+-- Iteration 10 --
+array(4) {
+  [1]=>
+  int(10)
+  [2]=>
+  int(20)
+  [4]=>
+  int(40)
+  [3]=>
+  int(30)
+}
+-- Iteration 11 --
+array(3) {
+  ["one"]=>
+  string(3) "ten"
+  ["two"]=>
+  string(6) "twenty"
+  ["three"]=>
+  string(6) "thirty"
+}
+-- Iteration 12 --
+array(3) {
+  ["one"]=>
+  int(1)
+  [2]=>
+  string(3) "two"
+  [4]=>
+  string(4) "four"
+}
+-- Iteration 13 --
+array(3) {
+  [""]=>
+  string(4) "null"
+  ["NULL"]=>
+  NULL
+  ["null"]=>
+  NULL
+}
+-- Iteration 14 --
+array(4) {
+  [1]=>
+  string(4) "true"
+  [0]=>
+  string(5) "false"
+  ["false"]=>
+  bool(false)
+  ["true"]=>
+  bool(true)
+}
+-- Iteration 15 --
+array(3) {
+  [""]=>
+  string(6) "emptys"
+  ["emptyd"]=>
+  string(0) ""
+  ["emptys"]=>
+  string(0) ""
+}
+-- Iteration 16 --
+array(6) {
+  [1]=>
+  string(0) ""
+  [2]=>
+  string(0) ""
+  [3]=>
+  NULL
+  [4]=>
+  NULL
+  [5]=>
+  bool(false)
+  [6]=>
+  bool(true)
+}
+-- Iteration 17 --
+array(3) {
+  [""]=>
+  int(4)
+  [0]=>
+  int(5)
+  [1]=>
+  int(6)
+}
+-- Iteration 18 --
+array(3) {
+  ["One"]=>
+  int(10)
+  ["two"]=>
+  int(20)
+  ["three"]=>
+  int(3)
+}
+Done
+--UEXPECTF--
+*** Testing array_map() : different arrays for 'arr1' argument ***
+-- Iteration 1 --
+array(2) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(2)
+}
+-- Iteration 2 --
+array(2) {
+  [0]=>
+  float(1.1)
+  [1]=>
+  float(2.2)
+}
+-- Iteration 3 --
+array(2) {
+  [0]=>
+  array(1) {
+    [0]=>
+    int(2)
+  }
+  [1]=>
+  array(1) {
+    [0]=>
+    int(1)
+  }
+}
+-- Iteration 4 --
+array(2) {
+  [0]=>
+  bool(false)
+  [1]=>
+  bool(true)
+}
+-- Iteration 5 --
+array(0) {
+}
+-- Iteration 6 --
+array(1) {
+  [0]=>
+  NULL
+}
+-- Iteration 7 --
+array(6) {
+  [0]=>
+  unicode(1) "a"
+  [1]=>
+  unicode(4) "aaaa"
+  [2]=>
+  unicode(1) "b"
+  [3]=>
+  unicode(4) "bbbb"
+  [4]=>
+  unicode(1) "c"
+  [5]=>
+  unicode(5) "ccccc"
+}
+-- Iteration 8 --
+array(3) {
+  [1]=>
+  unicode(3) "one"
+  [2]=>
+  unicode(3) "two"
+  [3]=>
+  unicode(5) "three"
+}
+-- Iteration 9 --
+array(3) {
+  [u"one"]=>
+  int(1)
+  [u"two"]=>
+  int(2)
+  [u"three"]=>
+  int(3)
+}
+-- Iteration 10 --
+array(4) {
+  [1]=>
+  int(10)
+  [2]=>
+  int(20)
+  [4]=>
+  int(40)
+  [3]=>
+  int(30)
+}
+-- Iteration 11 --
+array(3) {
+  [u"one"]=>
+  unicode(3) "ten"
+  [u"two"]=>
+  unicode(6) "twenty"
+  [u"three"]=>
+  unicode(6) "thirty"
+}
+-- Iteration 12 --
+array(3) {
+  [u"one"]=>
+  int(1)
+  [2]=>
+  unicode(3) "two"
+  [4]=>
+  unicode(4) "four"
+}
+-- Iteration 13 --
+array(3) {
+  [u""]=>
+  unicode(4) "null"
+  [u"NULL"]=>
+  NULL
+  [u"null"]=>
+  NULL
+}
+-- Iteration 14 --
+array(4) {
+  [1]=>
+  unicode(4) "true"
+  [0]=>
+  unicode(5) "false"
+  [u"false"]=>
+  bool(false)
+  [u"true"]=>
+  bool(true)
+}
+-- Iteration 15 --
+array(3) {
+  [u""]=>
+  unicode(6) "emptys"
+  [u"emptyd"]=>
+  unicode(0) ""
+  [u"emptys"]=>
+  unicode(0) ""
+}
+-- Iteration 16 --
+array(6) {
+  [1]=>
+  unicode(0) ""
+  [2]=>
+  unicode(0) ""
+  [3]=>
+  NULL
+  [4]=>
+  NULL
+  [5]=>
+  bool(false)
+  [6]=>
+  bool(true)
+}
+-- Iteration 17 --
+array(3) {
+  [u""]=>
+  int(4)
+  [0]=>
+  int(5)
+  [1]=>
+  int(6)
+}
+-- Iteration 18 --
+array(3) {
+  [u"One"]=>
+  int(10)
+  [u"two"]=>
+  int(20)
+  [u"three"]=>
+  int(3)
+}
+Done
\ No newline at end of file
diff --git a/ext/standard/tests/array/array_map_variation4.phpt b/ext/standard/tests/array/array_map_variation4.phpt
new file mode 100644 (file)
index 0000000..bbf975d
--- /dev/null
@@ -0,0 +1,280 @@
+--TEST--
+Test array_map() function : usage variations - associative array with different keys
+--FILE--
+<?php
+/* Prototype  : array array_map  ( callback $callback  , array $arr1  [, array $...  ] )
+ * Description: Applies the callback to the elements of the given arrays
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Test array_map() by passing associative array with different keys for $arr1 argument
+ */
+
+echo "*** Testing array_map() : associative array with diff. keys for 'arr1' argument ***\n";
+
+function callback($a)
+{
+  return ($a);
+}
+
+// get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get a resource variable
+$fp = fopen(__FILE__, "r");
+
+// get a class
+class classA{
+  public function __toString(){
+    return "Class A object";
+  }
+}
+
+// get a heredoc string
+$heredoc = <<<EOT
+Hello world
+EOT;
+
+// initializing the array
+$arrays = array (
+
+       // empty array
+/*1*/  array(),
+
+       // arrays with integer keys
+/*2*/  array(0 => "0"),
+       array(1 => "1"),
+       array(1 => "1", 2 => "2", 3 => "3", 4 => "4"),
+
+       // arrays with float keys
+/*5*/  array(2.3333 => "float"),
+       array(1.2 => "f1", 3.33 => "f2", 4.89999922839999 => "f3", 33333333.333333 => "f4"),
+
+       // arrays with string keys
+       array('\tHello' => 111, 're\td' => 'color', '\v\fworld' => 2.2, 'pen\n' => 33),
+/*8*/  array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 33),
+       array("hello", $heredoc => "string"), // heredoc
+
+       // array with object, unset variable and resource variable
+       array(new classA() => 11, @$unset_var => "hello", $fp => 'resource'),
+
+       // array with mixed values
+/*11*/ array('hello' => 1, new classA() => 2, "fruit" => 2.2, 
+              $fp => 'resource', 133 => "int", 444.432 => "float", 
+              @$unset_var => "unset", $heredoc => "heredoc")
+);
+
+// loop through the various elements of $arrays to test array_map()
+$iterator = 1;
+foreach($arrays as $arr1) {
+  echo "-- Iteration $iterator --\n";
+  var_dump( array_map('callback', $arr1) );
+  $iterator++;
+}
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_map() : associative array with diff. keys for 'arr1' argument ***
+
+Warning: Illegal offset type in %s on line %d%d
+
+Warning: Illegal offset type in %s on line %d%d
+
+Warning: Illegal offset type in %s on line %d%d
+
+Warning: Illegal offset type in %s on line %d%d
+-- Iteration 1 --
+array(0) {
+}
+-- Iteration 2 --
+array(1) {
+  [0]=>
+  string(1) "0"
+}
+-- Iteration 3 --
+array(1) {
+  [1]=>
+  string(1) "1"
+}
+-- Iteration 4 --
+array(4) {
+  [1]=>
+  string(1) "1"
+  [2]=>
+  string(1) "2"
+  [3]=>
+  string(1) "3"
+  [4]=>
+  string(1) "4"
+}
+-- Iteration 5 --
+array(1) {
+  [2]=>
+  string(5) "float"
+}
+-- Iteration 6 --
+array(4) {
+  [1]=>
+  string(2) "f1"
+  [3]=>
+  string(2) "f2"
+  [4]=>
+  string(2) "f3"
+  [33333333]=>
+  string(2) "f4"
+}
+-- Iteration 7 --
+array(4) {
+  ["\tHello"]=>
+  int(111)
+  ["re\td"]=>
+  string(5) "color"
+  ["\v\fworld"]=>
+  float(2.2)
+  ["pen\n"]=>
+  int(33)
+}
+-- Iteration 8 --
+array(4) {
+  ["   Hello"]=>
+  int(111)
+  ["re d"]=>
+  string(5) "color"
+  ["\v\fworld"]=>
+  float(2.2)
+  ["pen
+"]=>
+  int(33)
+}
+-- Iteration 9 --
+array(2) {
+  [0]=>
+  string(5) "hello"
+  ["Hello world"]=>
+  string(6) "string"
+}
+-- Iteration 10 --
+array(1) {
+  [""]=>
+  string(5) "hello"
+}
+-- Iteration 11 --
+array(6) {
+  ["hello"]=>
+  int(1)
+  ["fruit"]=>
+  float(2.2)
+  [133]=>
+  string(3) "int"
+  [444]=>
+  string(5) "float"
+  [""]=>
+  string(5) "unset"
+  ["Hello world"]=>
+  string(7) "heredoc"
+}
+Done
+--UEXPECTF--
+*** Testing array_map() : associative array with diff. keys for 'arr1' argument ***
+
+Warning: Illegal offset type in %s on line %d
+
+Warning: Illegal offset type in %s on line %d
+
+Warning: Illegal offset type in %s on line %d
+
+Warning: Illegal offset type in %s on line %d
+-- Iteration 1 --
+array(0) {
+}
+-- Iteration 2 --
+array(1) {
+  [0]=>
+  unicode(1) "0"
+}
+-- Iteration 3 --
+array(1) {
+  [1]=>
+  unicode(1) "1"
+}
+-- Iteration 4 --
+array(4) {
+  [1]=>
+  unicode(1) "1"
+  [2]=>
+  unicode(1) "2"
+  [3]=>
+  unicode(1) "3"
+  [4]=>
+  unicode(1) "4"
+}
+-- Iteration 5 --
+array(1) {
+  [2]=>
+  unicode(5) "float"
+}
+-- Iteration 6 --
+array(4) {
+  [1]=>
+  unicode(2) "f1"
+  [3]=>
+  unicode(2) "f2"
+  [4]=>
+  unicode(2) "f3"
+  [33333333]=>
+  unicode(2) "f4"
+}
+-- Iteration 7 --
+array(4) {
+  [u"\tHello"]=>
+  int(111)
+  [u"re\td"]=>
+  unicode(5) "color"
+  [u"\v\fworld"]=>
+  float(2.2)
+  [u"pen\n"]=>
+  int(33)
+}
+-- Iteration 8 --
+array(4) {
+  [u"  Hello"]=>
+  int(111)
+  [u"re        d"]=>
+  unicode(5) "color"
+  [u"\v\fworld"]=>
+  float(2.2)
+  [u"pen
+"]=>
+  int(33)
+}
+-- Iteration 9 --
+array(2) {
+  [0]=>
+  unicode(5) "hello"
+  [u"Hello world"]=>
+  unicode(6) "string"
+}
+-- Iteration 10 --
+array(1) {
+  [u""]=>
+  unicode(5) "hello"
+}
+-- Iteration 11 --
+array(6) {
+  [u"hello"]=>
+  int(1)
+  [u"fruit"]=>
+  float(2.2)
+  [133]=>
+  unicode(3) "int"
+  [444]=>
+  unicode(5) "float"
+  [u""]=>
+  unicode(5) "unset"
+  [u"Hello world"]=>
+  unicode(7) "heredoc"
+}
+Done
diff --git a/ext/standard/tests/array/array_map_variation5.phpt b/ext/standard/tests/array/array_map_variation5.phpt
new file mode 100644 (file)
index 0000000..fc469ef
--- /dev/null
@@ -0,0 +1,284 @@
+--TEST--
+Test array_map() function : usage variations - associative array with different values
+--FILE--
+<?php
+/* Prototype  : array array_map  ( callback $callback  , array $arr1  [, array $...  ] )
+ * Description: Applies the callback to the elements of the given arrays
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Test array_map() by passing associative array with different values for $arr1 argument
+ */
+
+echo "*** Testing array_map() : associative array with diff. values for 'arr1' argument ***\n";
+
+function callback($a)
+{
+  return ($a);
+}
+//get an unset variable
+$unset_var = array(1, 2);
+unset ($unset_var);
+
+//get a resource variable
+$fp = fopen(__FILE__, "r");
+
+//get a class
+class classA
+{
+  public function __toString(){
+    return "Class A object";
+  }
+}
+
+// get a heredoc string
+$heredoc = <<<EOT
+Hello world
+EOT;
+
+// initializing the array
+$arrays = array (
+
+       // empty array
+/*1*/  array(),
+
+       // arrays with integer values
+       array('0' => 0),
+       array("1" => 1),
+       array("one" => 1, 'two' => 2, "three" => 3, 4 => 4),
+
+       // arrays with float values
+/*5*/  array("float" => 2.3333),
+       array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.3333),
+
+       // arrays with string values
+       array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 =>  "pen\n"),
+/*8*/  array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 =>  'pen\n'),
+       array(1 => "hello", "heredoc" => $heredoc),
+
+       // array with object, unset variable and resource variable
+       array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp),
+
+       // array with mixed values
+/*11*/ array(1 => 'hello', 2 => new classA(), 222 => "fruit", 
+             'resource' => $fp, "int" => 133, "float" => 444.432, 
+             "unset" => @$unset_var, "heredoc" => $heredoc)
+);
+
+// loop through the various elements of $arrays to test array_map()
+$iterator = 1;
+foreach($arrays as $arr1) {
+  echo "-- Iteration $iterator --\n";
+  var_dump( array_map('callback', $arr1) );
+  $iterator++;
+}
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_map() : associative array with diff. values for 'arr1' argument ***
+-- Iteration 1 --
+array(0) {
+}
+-- Iteration 2 --
+array(1) {
+  [0]=>
+  int(0)
+}
+-- Iteration 3 --
+array(1) {
+  [1]=>
+  int(1)
+}
+-- Iteration 4 --
+array(4) {
+  ["one"]=>
+  int(1)
+  ["two"]=>
+  int(2)
+  ["three"]=>
+  int(3)
+  [4]=>
+  int(4)
+}
+-- Iteration 5 --
+array(1) {
+  ["float"]=>
+  float(2.3333)
+}
+-- Iteration 6 --
+array(4) {
+  ["f1"]=>
+  float(1.2)
+  ["f2"]=>
+  float(3.33)
+  [3]=>
+  float(4.8999992284)
+  ["f4"]=>
+  float(33333333.3333)
+}
+-- Iteration 7 --
+array(4) {
+  [111]=>
+  string(6) "  Hello"
+  ["red"]=>
+  string(6) "col       or"
+  [2]=>
+  string(7) "\v\fworld"
+  [3]=>
+  string(4) "pen
+"
+}
+-- Iteration 8 --
+array(4) {
+  [111]=>
+  string(7) "\tHello"
+  ["red"]=>
+  string(7) "col\tor"
+  [2]=>
+  string(9) "\v\fworld"
+  [3]=>
+  string(5) "pen\n"
+}
+-- Iteration 9 --
+array(2) {
+  [1]=>
+  string(5) "hello"
+  ["heredoc"]=>
+  string(11) "Hello world"
+}
+-- Iteration 10 --
+array(3) {
+  [11]=>
+  object(classA)#%d (0) {
+  }
+  ["unset"]=>
+  NULL
+  ["resource"]=>
+  resource(%d) of type (stream)
+}
+-- Iteration 11 --
+array(8) {
+  [1]=>
+  string(5) "hello"
+  [2]=>
+  object(classA)#%d (0) {
+  }
+  [222]=>
+  string(5) "fruit"
+  ["resource"]=>
+  resource(%d) of type (stream)
+  ["int"]=>
+  int(133)
+  ["float"]=>
+  float(444.432)
+  ["unset"]=>
+  NULL
+  ["heredoc"]=>
+  string(11) "Hello world"
+}
+Done
+--UEXPECTF--
+*** Testing array_map() : associative array with diff. values for 'arr1' argument ***
+-- Iteration 1 --
+array(0) {
+}
+-- Iteration 2 --
+array(1) {
+  [0]=>
+  int(0)
+}
+-- Iteration 3 --
+array(1) {
+  [1]=>
+  int(1)
+}
+-- Iteration 4 --
+array(4) {
+  [u"one"]=>
+  int(1)
+  [u"two"]=>
+  int(2)
+  [u"three"]=>
+  int(3)
+  [4]=>
+  int(4)
+}
+-- Iteration 5 --
+array(1) {
+  [u"float"]=>
+  float(2.3333)
+}
+-- Iteration 6 --
+array(4) {
+  [u"f1"]=>
+  float(1.2)
+  [u"f2"]=>
+  float(3.33)
+  [3]=>
+  float(4.8999992284)
+  [u"f4"]=>
+  float(33333333.3333)
+}
+-- Iteration 7 --
+array(4) {
+  [111]=>
+  unicode(6) " Hello"
+  [u"red"]=>
+  unicode(6) "col      or"
+  [2]=>
+  unicode(7) "\v\fworld"
+  [3]=>
+  unicode(4) "pen
+"
+}
+-- Iteration 8 --
+array(4) {
+  [111]=>
+  unicode(7) "\tHello"
+  [u"red"]=>
+  unicode(7) "col\tor"
+  [2]=>
+  unicode(9) "\v\fworld"
+  [3]=>
+  unicode(5) "pen\n"
+}
+-- Iteration 9 --
+array(2) {
+  [1]=>
+  unicode(5) "hello"
+  [u"heredoc"]=>
+  unicode(11) "Hello world"
+}
+-- Iteration 10 --
+array(3) {
+  [11]=>
+  object(classA)#1 (0) {
+  }
+  [u"unset"]=>
+  NULL
+  [u"resource"]=>
+  resource(%d) of type (stream)
+}
+-- Iteration 11 --
+array(8) {
+  [1]=>
+  unicode(5) "hello"
+  [2]=>
+  object(classA)#%d (0) {
+  }
+  [222]=>
+  unicode(5) "fruit"
+  [u"resource"]=>
+  resource(%d) of type (stream)
+  [u"int"]=>
+  int(133)
+  [u"float"]=>
+  float(444.432)
+  [u"unset"]=>
+  NULL
+  [u"heredoc"]=>
+  unicode(11) "Hello world"
+}
+Done
diff --git a/ext/standard/tests/array/array_map_variation6.phpt b/ext/standard/tests/array/array_map_variation6.phpt
new file mode 100644 (file)
index 0000000..ffc34b7
--- /dev/null
@@ -0,0 +1,112 @@
+--TEST--
+Test array_map() function : usage variations - array having subarrays
+--FILE--
+<?php
+/* Prototype  : array array_map  ( callback $callback  , array $arr1  [, array $...  ] )
+ * Description: Applies the callback to the elements of the given arrays 
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Test array_map() by passing array having different subarrays
+ */
+
+echo "*** Testing array_map() : array having subarrays ***\n";
+
+function callback($a)
+{
+  return $a;
+}
+
+// different subarrays
+$arr1 = array(
+  array(),
+  array(1, 2),
+  array('a', 'b'),
+  array(1, 2, 'a', 'b'),
+  array(1 => 'a', 'b' => 2)
+);  
+
+var_dump( array_map('callback', $arr1));
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_map() : array having subarrays ***
+array(5) {
+  [0]=>
+  array(0) {
+  }
+  [1]=>
+  array(2) {
+    [0]=>
+    int(1)
+    [1]=>
+    int(2)
+  }
+  [2]=>
+  array(2) {
+    [0]=>
+    string(1) "a"
+    [1]=>
+    string(1) "b"
+  }
+  [3]=>
+  array(4) {
+    [0]=>
+    int(1)
+    [1]=>
+    int(2)
+    [2]=>
+    string(1) "a"
+    [3]=>
+    string(1) "b"
+  }
+  [4]=>
+  array(2) {
+    [1]=>
+    string(1) "a"
+    ["b"]=>
+    int(2)
+  }
+}
+Done
+--UEXPECTF--
+*** Testing array_map() : array having subarrays ***
+array(5) {
+  [0]=>
+  array(0) {
+  }
+  [1]=>
+  array(2) {
+    [0]=>
+    int(1)
+    [1]=>
+    int(2)
+  }
+  [2]=>
+  array(2) {
+    [0]=>
+    unicode(1) "a"
+    [1]=>
+    unicode(1) "b"
+  }
+  [3]=>
+  array(4) {
+    [0]=>
+    int(1)
+    [1]=>
+    int(2)
+    [2]=>
+    unicode(1) "a"
+    [3]=>
+    unicode(1) "b"
+  }
+  [4]=>
+  array(2) {
+    [1]=>
+    unicode(1) "a"
+    [u"b"]=>
+    int(2)
+  }
+}
+Done
\ No newline at end of file
diff --git a/ext/standard/tests/array/array_map_variation7.phpt b/ext/standard/tests/array/array_map_variation7.phpt
new file mode 100644 (file)
index 0000000..412f50a
--- /dev/null
@@ -0,0 +1,210 @@
+--TEST--
+Test array_map() function : usage variations - arrays of different size
+--FILE--
+<?php
+/* Prototype  : array array_map  ( callback $callback  , array $arr1  [, array $...  ] )
+ * Description: Applies the callback to the elements of the given arrays 
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Test array_map() by passing array having different size
+ *   1) first array as empty array
+ *   2) second array as empty array
+ *   3) second array shorter than first array
+ *   4) first array shorter than second array
+ *   5) one more array than callback function arguments
+ */
+
+echo "*** Testing array_map() : arrays with diff. size ***\n";
+
+function callback($a, $b)
+{
+  return array($a => $b);
+}
+
+// calling array_map with different arrays
+var_dump( array_map('callback', array(1, 2, 3), array()) );
+var_dump( array_map('callback', array(), array('a', 'b', 'c')) );
+var_dump( array_map('callback', array(1, 2, 3), array('a', 'b')) );
+var_dump( array_map('callback', array(012, 0x2F, 0X1A), array(2.3, 12.4e2)) );
+var_dump( array_map('callback', array(), array(1, 2, 3), array('a', 'b')) );  // passing more no. of arrays than callback function argument
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_map() : arrays with diff. size ***
+array(3) {
+  [0]=>
+  array(1) {
+    [1]=>
+    NULL
+  }
+  [1]=>
+  array(1) {
+    [2]=>
+    NULL
+  }
+  [2]=>
+  array(1) {
+    [3]=>
+    NULL
+  }
+}
+array(3) {
+  [0]=>
+  array(1) {
+    [""]=>
+    string(1) "a"
+  }
+  [1]=>
+  array(1) {
+    [""]=>
+    string(1) "b"
+  }
+  [2]=>
+  array(1) {
+    [""]=>
+    string(1) "c"
+  }
+}
+array(3) {
+  [0]=>
+  array(1) {
+    [1]=>
+    string(1) "a"
+  }
+  [1]=>
+  array(1) {
+    [2]=>
+    string(1) "b"
+  }
+  [2]=>
+  array(1) {
+    [3]=>
+    NULL
+  }
+}
+array(3) {
+  [0]=>
+  array(1) {
+    [10]=>
+    float(2.3)
+  }
+  [1]=>
+  array(1) {
+    [47]=>
+    float(1240)
+  }
+  [2]=>
+  array(1) {
+    [26]=>
+    NULL
+  }
+}
+array(3) {
+  [0]=>
+  array(1) {
+    [""]=>
+    int(1)
+  }
+  [1]=>
+  array(1) {
+    [""]=>
+    int(2)
+  }
+  [2]=>
+  array(1) {
+    [""]=>
+    int(3)
+  }
+}
+Done
+--UEXPECTF--
+*** Testing array_map() : arrays with diff. size ***
+array(3) {
+  [0]=>
+  array(1) {
+    [1]=>
+    NULL
+  }
+  [1]=>
+  array(1) {
+    [2]=>
+    NULL
+  }
+  [2]=>
+  array(1) {
+    [3]=>
+    NULL
+  }
+}
+array(3) {
+  [0]=>
+  array(1) {
+    [u""]=>
+    unicode(1) "a"
+  }
+  [1]=>
+  array(1) {
+    [u""]=>
+    unicode(1) "b"
+  }
+  [2]=>
+  array(1) {
+    [u""]=>
+    unicode(1) "c"
+  }
+}
+array(3) {
+  [0]=>
+  array(1) {
+    [1]=>
+    unicode(1) "a"
+  }
+  [1]=>
+  array(1) {
+    [2]=>
+    unicode(1) "b"
+  }
+  [2]=>
+  array(1) {
+    [3]=>
+    NULL
+  }
+}
+array(3) {
+  [0]=>
+  array(1) {
+    [10]=>
+    float(2.3)
+  }
+  [1]=>
+  array(1) {
+    [47]=>
+    float(1240)
+  }
+  [2]=>
+  array(1) {
+    [26]=>
+    NULL
+  }
+}
+array(3) {
+  [0]=>
+  array(1) {
+    [u""]=>
+    int(1)
+  }
+  [1]=>
+  array(1) {
+    [u""]=>
+    int(2)
+  }
+  [2]=>
+  array(1) {
+    [u""]=>
+    int(3)
+  }
+}
+Done
\ No newline at end of file
diff --git a/ext/standard/tests/array/array_map_variation8.phpt b/ext/standard/tests/array/array_map_variation8.phpt
new file mode 100644 (file)
index 0000000..293d3be
--- /dev/null
@@ -0,0 +1,114 @@
+--TEST--
+Test array_map() function : usage variations - array with references
+--FILE--
+<?php
+/* Prototype  : array array_map  ( callback $callback  , array $arr1  [, array $...  ] )
+ * Description: Applies the callback to the elements of the given arrays
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Test array_map() by passing array having reference values for $arr1 argument
+ */
+
+echo "*** Testing array_map() : array with references for 'arr1' argument ***\n";
+
+function callback1($a)
+{
+  return ($a);
+}
+
+function callback_cat($a, $b)
+{
+  return ($a . $b);
+}
+
+// reference variables
+$value1 = 10;
+$value2 = "hello";
+$value3 = 0;
+$value4 = &$value2;
+
+// array containing reference variables
+$arr1 = array(
+  0 => 0,
+  1 => &$value4,
+  2 => &$value2,
+  3 => "hello",
+  4 => &$value3,
+  $value4 => &$value2
+);
+echo "-- with one array --\n";
+var_dump( array_map('callback1', $arr1) );
+
+echo "-- with two arrays --\n";
+var_dump( array_map('callback_cat', $arr1, $arr1) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_map() : array with references for 'arr1' argument ***
+-- with one array --
+array(6) {
+  [0]=>
+  int(0)
+  [1]=>
+  string(5) "hello"
+  [2]=>
+  string(5) "hello"
+  [3]=>
+  string(5) "hello"
+  [4]=>
+  int(0)
+  ["hello"]=>
+  string(5) "hello"
+}
+-- with two arrays --
+array(6) {
+  [0]=>
+  string(2) "00"
+  [1]=>
+  string(10) "hellohello"
+  [2]=>
+  string(10) "hellohello"
+  [3]=>
+  string(10) "hellohello"
+  [4]=>
+  string(2) "00"
+  [5]=>
+  string(10) "hellohello"
+}
+Done
+--UEXPECTF--
+*** Testing array_map() : array with references for 'arr1' argument ***
+-- with one array --
+array(6) {
+  [0]=>
+  int(0)
+  [1]=>
+  unicode(5) "hello"
+  [2]=>
+  unicode(5) "hello"
+  [3]=>
+  unicode(5) "hello"
+  [4]=>
+  int(0)
+  [u"hello"]=>
+  unicode(5) "hello"
+}
+-- with two arrays --
+array(6) {
+  [0]=>
+  unicode(2) "00"
+  [1]=>
+  unicode(10) "hellohello"
+  [2]=>
+  unicode(10) "hellohello"
+  [3]=>
+  unicode(10) "hellohello"
+  [4]=>
+  unicode(2) "00"
+  [5]=>
+  unicode(10) "hellohello"
+}
+Done
\ No newline at end of file
diff --git a/ext/standard/tests/array/array_map_variation9.phpt b/ext/standard/tests/array/array_map_variation9.phpt
new file mode 100644 (file)
index 0000000..dc28838
--- /dev/null
@@ -0,0 +1,141 @@
+--TEST--
+Test array_map() function : usage variations - binary safe checking
+--FILE--
+<?php
+/* Prototype  : array array_map  ( callback $callback  , array $arr1  [, array $...  ] )
+ * Description: Applies the callback to the elements of the given arrays
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Test array_map() by passing array having binary values for $arr1 argument
+ */
+
+echo "*** Testing array_map() : array with binary data for 'arr1' argument ***\n";
+
+function callback1($a)
+{
+  return ($a);
+}
+function callback2($a, $b)
+{
+  return array($a => $b);
+}
+
+// array with binary data
+$arr1 = array(b"hello", b"world", "1", b"22.22");
+
+echo "-- checking binary safe array with one parameter callback function --\n";
+var_dump( array_map('callback1', $arr1) );
+
+echo "-- checking binary safe array with two parameter callback function --\n";
+var_dump( array_map(b"callback2", $arr1) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_map() : array with binary data for 'arr1' argument ***
+-- checking binary safe array with one parameter callback function --
+array(4) {
+  [0]=>
+  string(5) "hello"
+  [1]=>
+  string(5) "world"
+  [2]=>
+  string(1) "1"
+  [3]=>
+  string(5) "22.22"
+}
+-- checking binary safe array with two parameter callback function --
+
+Warning: Missing argument 2 for callback2() in %s on line %d%d
+
+Notice: Undefined variable: b in %s on line %d%d
+
+Warning: Missing argument 2 for callback2() in %s on line %d%d
+
+Notice: Undefined variable: b in %s on line %d%d
+
+Warning: Missing argument 2 for callback2() in %s on line %d%d
+
+Notice: Undefined variable: b in %s on line %d%d
+
+Warning: Missing argument 2 for callback2() in %s on line %d%d
+
+Notice: Undefined variable: b in %s on line %d%d
+array(4) {
+  [0]=>
+  array(1) {
+    ["hello"]=>
+    NULL
+  }
+  [1]=>
+  array(1) {
+    ["world"]=>
+    NULL
+  }
+  [2]=>
+  array(1) {
+    [1]=>
+    NULL
+  }
+  [3]=>
+  array(1) {
+    ["22.22"]=>
+    NULL
+  }
+}
+Done
+--UEXPECTF--
+*** Testing array_map() : array with binary data for 'arr1' argument ***
+-- checking binary safe array with one parameter callback function --
+array(4) {
+  [0]=>
+  string(5) "hello"
+  [1]=>
+  string(5) "world"
+  [2]=>
+  unicode(1) "1"
+  [3]=>
+  string(5) "22.22"
+}
+-- checking binary safe array with two parameter callback function --
+
+Warning: Missing argument 2 for callback2() in %s on line %d
+
+Notice: Undefined variable: b in %s on line %d
+
+Warning: Missing argument 2 for callback2() in %s on line %d
+
+Notice: Undefined variable: b in %s on line %d
+
+Warning: Missing argument 2 for callback2() in %s on line %d
+
+Notice: Undefined variable: b in %s on line %d
+
+Warning: Missing argument 2 for callback2() in %s on line %d
+
+Notice: Undefined variable: b in %s on line %d
+array(4) {
+  [0]=>
+  array(1) {
+    ["hello"]=>
+    NULL
+  }
+  [1]=>
+  array(1) {
+    ["world"]=>
+    NULL
+  }
+  [2]=>
+  array(1) {
+    [1]=>
+    NULL
+  }
+  [3]=>
+  array(1) {
+    ["22.22"]=>
+    NULL
+  }
+}
+Done