PageRenderTime 59ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/standard/tests/array/array_diff_uassoc_variation3.php

http://github.com/facebook/hiphop-php
PHP | 107 lines | 60 code | 23 blank | 24 comment | 0 complexity | c362d74cc520af9f24bfe7fdf6c4b1fd MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. /* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func)
  3. * Description: Computes the difference of arrays with additional index check which is performed by a
  4. * user supplied callback function
  5. * Source code: ext/standard/array.c
  6. */
  7. echo "*** Testing array_diff_uassoc() : usage variation ***\n";
  8. //Initialize array
  9. $array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
  10. $array2 = array("a" => "green", "yellow", "red");
  11. //get an unset variable
  12. $unset_var = 10;
  13. unset ($unset_var);
  14. //resource variable
  15. $fp = fopen(__FILE__, "r");
  16. // define some classes
  17. class classWithToString
  18. {
  19. public function __toString() {
  20. return "Class A object";
  21. }
  22. }
  23. class classWithoutToString
  24. {
  25. }
  26. // heredoc string
  27. $heredoc = <<<EOT
  28. hello world
  29. EOT;
  30. // add arrays
  31. $index_array = array (1, 2, 3);
  32. $assoc_array = array ('one' => 1, 'two' => 2);
  33. //array of values to iterate over
  34. $inputs = array(
  35. // int data
  36. 'int 0' => 0,
  37. 'int 1' => 1,
  38. 'int 12345' => 12345,
  39. 'int -12345' => -12345,
  40. // float data
  41. 'float 10.5' => 10.5,
  42. 'float -10.5' => -10.5,
  43. 'float 12.3456789000e10' => 12.3456789000e10,
  44. 'float -12.3456789000e10' => -12.3456789000e10,
  45. 'float .5' => .5,
  46. // array data
  47. 'empty array' => array(),
  48. 'int indexed array' => $index_array,
  49. 'associative array' => $assoc_array,
  50. 'nested arrays' => array('foo', $index_array, $assoc_array),
  51. // null data
  52. 'uppercase NULL' => NULL,
  53. 'lowercase null' => null,
  54. // boolean data
  55. 'lowercase true' => true,
  56. 'lowercase false' =>false,
  57. 'uppercase TRUE' =>TRUE,
  58. 'uppercase FALSE' =>FALSE,
  59. // empty data
  60. 'empty string DQ' => "",
  61. 'empty string SQ' => '',
  62. // string data
  63. 'string DQ' => "string",
  64. 'string SQ' => 'string',
  65. 'mixed case string' => "sTrInG",
  66. 'heredoc' => $heredoc,
  67. // object data
  68. 'instance of classWithToString' => new classWithToString(),
  69. 'instance of classWithoutToString' => new classWithoutToString(),
  70. // undefined data
  71. 'undefined var' => @$undefined_var,
  72. // unset data
  73. 'unset var' => @$unset_var,
  74. // resource data
  75. 'resource' => $fp,
  76. );
  77. // loop through each element of the array for key_comp_func
  78. foreach($inputs as $key =>$value) {
  79. echo "\n--$key--\n";
  80. var_dump( array_diff_uassoc($array1, $array2, $value) );
  81. };
  82. fclose($fp);
  83. ?>
  84. ===DONE===