unset_non_array.phpt 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. --TEST--
  2. Unset on non-array
  3. --FILE--
  4. <?php
  5. unset($x[0]);
  6. $x = null;
  7. unset($x[0]);
  8. $x = false;
  9. unset($x[0]);
  10. $x = true;
  11. try {
  12. unset($x[0]);
  13. } catch (Error $e) {
  14. echo $e->getMessage(), "\n";
  15. }
  16. $x = 1;
  17. try {
  18. unset($x[0]);
  19. } catch (Error $e) {
  20. echo $e->getMessage(), "\n";
  21. }
  22. $x = 3.14;
  23. try {
  24. unset($x[0]);
  25. } catch (Error $e) {
  26. echo $e->getMessage(), "\n";
  27. }
  28. $x = "str";
  29. try {
  30. unset($x[0]);
  31. } catch (Error $e) {
  32. echo $e->getMessage(), "\n";
  33. }
  34. $x = new stdClass;
  35. try {
  36. unset($x[0]);
  37. } catch (Error $e) {
  38. echo $e->getMessage(), "\n";
  39. }
  40. // And now repeat the same with a nested offset.
  41. unset($x);
  42. unset($x[0][0]);
  43. $x = null;
  44. unset($x[0][0]);
  45. $x = false;
  46. unset($x[0][0]);
  47. $x = true;
  48. try {
  49. unset($x[0][0]);
  50. } catch (Error $e) {
  51. echo $e->getMessage(), "\n";
  52. }
  53. $x = 1;
  54. try {
  55. unset($x[0][0]);
  56. } catch (Error $e) {
  57. echo $e->getMessage(), "\n";
  58. }
  59. $x = 3.14;
  60. try {
  61. unset($x[0][0]);
  62. } catch (Error $e) {
  63. echo $e->getMessage(), "\n";
  64. }
  65. $x = "str";
  66. try {
  67. unset($x[0][0]);
  68. } catch (Error $e) {
  69. echo $e->getMessage(), "\n";
  70. }
  71. $x = new stdClass;
  72. try {
  73. unset($x[0][0]);
  74. } catch (Error $e) {
  75. echo $e->getMessage(), "\n";
  76. }
  77. ?>
  78. --EXPECTF--
  79. Warning: Undefined variable $x in %s on line %d
  80. Deprecated: Automatic conversion of false to array is deprecated in %s
  81. Cannot unset offset in a non-array variable
  82. Cannot unset offset in a non-array variable
  83. Cannot unset offset in a non-array variable
  84. Cannot unset string offsets
  85. Cannot use object of type stdClass as array
  86. Warning: Undefined variable $x in %s on line %d
  87. Deprecated: Automatic conversion of false to array is deprecated in %s
  88. Cannot unset offset in a non-array variable
  89. Cannot unset offset in a non-array variable
  90. Cannot unset offset in a non-array variable
  91. Cannot unset string offsets
  92. Cannot use object of type stdClass as array