PageRenderTime 23ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/facebook/hiphop-php
PHP | 100 lines | 57 code | 21 blank | 22 comment | 0 complexity | 32b5c29302ada4db3ea332248e372974 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_udiff_assoc(array arr1, array arr2 [, array ...], callback key_comp_func)
  3. * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments but do additional checks whether the keys are equal. Keys are compared by user supplied function.
  4. * Source code: ext/standard/array.c
  5. * Alias to functions:
  6. */
  7. echo "*** Testing array_udiff_assoc() : usage variation ***\n";
  8. // Initialise function arguments not being substituted (if any)
  9. $arr1 = array(1, 2);
  10. $arr2 = array(1, 2);
  11. //get an unset variable
  12. $unset_var = 10;
  13. unset ($unset_var);
  14. // define some classes
  15. class classWithToString
  16. {
  17. public function __toString() {
  18. return "Class A object";
  19. }
  20. }
  21. class classWithoutToString
  22. {
  23. }
  24. // heredoc string
  25. $heredoc = <<<EOT
  26. hello world
  27. EOT;
  28. // add arrays
  29. $index_array = array (1, 2, 3);
  30. $assoc_array = array ('one' => 1, 'two' => 2);
  31. //array of values to iterate over
  32. $inputs = array(
  33. // int data
  34. 'int 0' => 0,
  35. 'int 1' => 1,
  36. 'int 12345' => 12345,
  37. 'int -12345' => -2345,
  38. // float data
  39. 'float 10.5' => 10.5,
  40. 'float -10.5' => -10.5,
  41. 'float 12.3456789000e10' => 12.3456789000e10,
  42. 'float -12.3456789000e10' => -12.3456789000e10,
  43. 'float .5' => .5,
  44. // array data
  45. 'empty array' => array(),
  46. 'int indexed array' => $index_array,
  47. 'associative array' => $assoc_array,
  48. 'nested arrays' => array('foo', $index_array, $assoc_array),
  49. // null data
  50. 'uppercase NULL' => NULL,
  51. 'lowercase null' => null,
  52. // boolean data
  53. 'lowercase true' => true,
  54. 'lowercase false' =>false,
  55. 'uppercase TRUE' =>TRUE,
  56. 'uppercase FALSE' =>FALSE,
  57. // empty data
  58. 'empty string DQ' => "",
  59. 'empty string SQ' => '',
  60. // string data
  61. 'string DQ' => "string",
  62. 'string SQ' => 'string',
  63. 'mixed case string' => "sTrInG",
  64. 'heredoc' => $heredoc,
  65. // object data
  66. 'instance of classWithToString' => new classWithToString(),
  67. 'instance of classWithoutToString' => new classWithoutToString(),
  68. // undefined data
  69. 'undefined var' => @$undefined_var,
  70. // unset data
  71. 'unset var' => @$unset_var,
  72. );
  73. // loop through each element of the array for key_comp_func
  74. foreach($inputs as $key =>$value) {
  75. echo "\n--$key--\n";
  76. var_dump( array_udiff_assoc($arr1, $arr2, $value) );
  77. };
  78. ?>
  79. ===DONE===