falsetoarray.phpt 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. --TEST--
  2. Autovivification of false to array
  3. --FILE--
  4. <?php
  5. // control
  6. $undef[] = 42;
  7. // control
  8. $null = null;
  9. $null[] = 42;
  10. // control
  11. $false = false;
  12. $false = [42];
  13. print "[001]\n";
  14. $false = false;
  15. $false[] = 42;
  16. print "[002]\n";
  17. $ref = false;
  18. $ref2 = &$ref;
  19. $ref2[] = 42;
  20. echo "\nFunction\n";
  21. function ffalse(bool $a, ?bool $b, &$c, ...$d) {
  22. print "[003]\n";
  23. $a[] = 42;
  24. print "[004]\n";
  25. $b[] = 42;
  26. print "[005]\n";
  27. $c[] = 42;
  28. print "[006]\n";
  29. $d[0][] = 42;
  30. }
  31. $ref = false;
  32. ffalse(false, false, $ref, false);
  33. echo "\nProperties\n";
  34. class Cfalse {
  35. public $def;
  36. private $untyped = false;
  37. static private $st = false;
  38. static private $st2 = false;
  39. static private $st3 = false;
  40. public function __construct(public $pu, private $pr = false) {
  41. print "[007]\n";
  42. $this->def = false;
  43. $this->def[] = 42;
  44. print "[008]\n";
  45. $this->untyped[] = 42;
  46. print "[009]\n";
  47. self::$st[] = 42;
  48. print "[010]\n";
  49. static::$st2[] = 42;
  50. print "[011]\n";
  51. $this::$st3[] = 42;
  52. print "[012]\n";
  53. $this->pu[] = 42;
  54. print "[013]\n";
  55. $this->pr[] = 42;
  56. }
  57. }
  58. new Cfalse(false, false);
  59. echo "\nDestructuring\n";
  60. print "[014]\n";
  61. $add = false;
  62. foreach ([42] as $add[]);
  63. print "[015]\n";
  64. $arr = false;
  65. [$arr[]] = [42];
  66. print "[016]\n";
  67. $arr = [ 0 => [ 0 => false ] ];
  68. $arr[0][0][0][] = 42;
  69. print "[017]\n";
  70. $false = false;
  71. $r42 = 42;
  72. $false[] &= $r42;
  73. $false = false;
  74. $false2 = false;
  75. $false3 = false;
  76. function &g(){
  77. print "[018]\n";
  78. global $false;
  79. $false[] = 42;
  80. $var1 = false;
  81. $GLOBALS["false2"] =& $var1;
  82. print "[019]\n";
  83. $GLOBALS["false3"][] = 42;
  84. print "[020]\n";
  85. static $f2 = false;
  86. return $f2;
  87. }
  88. $false = &g();
  89. $false[] = 42;
  90. print "[021]\n";
  91. $false2[] = 42;
  92. print "[022]\n";
  93. $a = false;
  94. unset($a[0][0]);
  95. print "[023]\n";
  96. $a = false;
  97. unset($a[0]);
  98. ?>
  99. --EXPECTF--
  100. [001]
  101. Deprecated: Automatic conversion of false to array is deprecated in %s
  102. [002]
  103. Deprecated: Automatic conversion of false to array is deprecated in %s
  104. Function
  105. [003]
  106. Deprecated: Automatic conversion of false to array is deprecated in %s
  107. [004]
  108. Deprecated: Automatic conversion of false to array is deprecated in %s
  109. [005]
  110. Deprecated: Automatic conversion of false to array is deprecated in %s
  111. [006]
  112. Deprecated: Automatic conversion of false to array is deprecated in %s
  113. Properties
  114. [007]
  115. Deprecated: Automatic conversion of false to array is deprecated in %s
  116. [008]
  117. Deprecated: Automatic conversion of false to array is deprecated in %s
  118. [009]
  119. Deprecated: Automatic conversion of false to array is deprecated in %s
  120. [010]
  121. Deprecated: Automatic conversion of false to array is deprecated in %s
  122. [011]
  123. Deprecated: Automatic conversion of false to array is deprecated in %s
  124. [012]
  125. Deprecated: Automatic conversion of false to array is deprecated in %s
  126. [013]
  127. Deprecated: Automatic conversion of false to array is deprecated in %s
  128. Destructuring
  129. [014]
  130. Deprecated: Automatic conversion of false to array is deprecated in %s
  131. [015]
  132. Deprecated: Automatic conversion of false to array is deprecated in %s
  133. [016]
  134. Deprecated: Automatic conversion of false to array is deprecated in %s
  135. [017]
  136. Deprecated: Automatic conversion of false to array is deprecated in %s
  137. [018]
  138. Deprecated: Automatic conversion of false to array is deprecated in %s
  139. [019]
  140. Deprecated: Automatic conversion of false to array is deprecated in %s
  141. [020]
  142. Deprecated: Automatic conversion of false to array is deprecated in %s
  143. [021]
  144. Deprecated: Automatic conversion of false to array is deprecated in %s
  145. [022]
  146. Deprecated: Automatic conversion of false to array is deprecated in %s
  147. [023]
  148. Deprecated: Automatic conversion of false to array is deprecated in %s