object_handlers.phpt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. --TEST--
  2. Magic object handlers segfaults and memory errors
  3. --FILE--
  4. <?php
  5. function f($x) {
  6. return $x;
  7. }
  8. class foo implements ArrayAccess {
  9. function __get($property) {
  10. $GLOBALS["y"] = $property;
  11. }
  12. function __set($property, $value) {
  13. $GLOBALS["y"] = $property;
  14. }
  15. function __call($func, $args) {
  16. $GLOBALS["y"] = $func;
  17. }
  18. static function __callStatic($func, $args) {
  19. $GLOBALS["y"] = $func;
  20. }
  21. function offsetGet($index) {
  22. $GLOBALS["y"] = $index;
  23. }
  24. function offsetSet($index, $newval) {
  25. $GLOBALS["y"] = $index;
  26. }
  27. function offsetExists($index) {
  28. $GLOBALS["y"] = $index;
  29. }
  30. function offsetUnset($index) {
  31. $GLOBALS["y"] = $index;
  32. }
  33. }
  34. $x = new foo();
  35. $y = null;
  36. // IS_CONST
  37. $z = $x->const_get;
  38. echo $y,"\n";
  39. $x->const_set = 1;
  40. echo $y,"\n";
  41. $x->const_call();
  42. echo $y,"\n";
  43. foo::const_callstatic();
  44. echo $y,"\n";
  45. $z = $x["const_dim_get"];
  46. echo $y,"\n";
  47. $x["const_dim_set"] = 1;
  48. echo $y,"\n";
  49. isset($x["const_dim_isset"]);
  50. echo $y,"\n";
  51. unset($x["const_dim_unset"]);
  52. echo $y,"\n";
  53. // IS_CONST + conversion
  54. $z = $x->{1};
  55. echo $y,"\n";
  56. $x->{2} = 1;
  57. echo $y,"\n";
  58. // IS_TMP_VAR
  59. $c = "tmp";
  60. $z = $x->{$c."_get"};
  61. echo $y,"\n";
  62. $x->{$c."_set"} = 1;
  63. echo $y,"\n";
  64. $x->{$c."_call"}();
  65. echo $y,"\n";
  66. $z = $x[$c."_dim_get"];
  67. echo $y,"\n";
  68. $x[$c."_dim_set"] = 1;
  69. echo $y,"\n";
  70. isset($x[$c."_dim_isset"]);
  71. echo $y,"\n";
  72. unset($x[$c."_dim_unset"]);
  73. echo $y,"\n";
  74. // IS_TMP_VAR + conversion
  75. $c = 0;
  76. $z = $x->{$c+3};
  77. echo $y,"\n";
  78. $x->{$c+4} = 1;
  79. echo $y,"\n";
  80. // IS_CV
  81. $c = "cv_get";
  82. $z = $x->{$c};
  83. echo $y,"\n";
  84. $c = "cv_set";
  85. $x->{$c} = 1;
  86. echo $y,"\n";
  87. $c = "cv_call";
  88. $x->{$c}();
  89. echo $y,"\n";
  90. $c = "cv_dim_get";
  91. $z = $x[$c];
  92. echo $y,"\n";
  93. $c = "cv_dim_set";
  94. $x[$c] = 1;
  95. echo $y,"\n";
  96. $c = "cv_dim_isset";
  97. isset($x[$c]);
  98. echo $y,"\n";
  99. $c = "cv_dim_unset";
  100. unset($x[$c]);
  101. echo $y,"\n";
  102. // IS_CV + conversion
  103. $c = 5;
  104. $z = $x->{$c};
  105. echo $y,"\n";
  106. $c = 6;
  107. $x->{$c} = 1;
  108. echo $y,"\n";
  109. // IS_VAR
  110. $z = $x->{f("var_get")};
  111. echo $y,"\n";
  112. $x->{f("var_set")} = 1;
  113. echo $y,"\n";
  114. $x->{f("var_call")}();
  115. echo $y,"\n";
  116. $z = $x[f("var_dim_get")];
  117. echo $y,"\n";
  118. $x[f("var_dim_set")] = 1;
  119. echo $y,"\n";
  120. isset($x[f("var_dim_isset")]);
  121. echo $y,"\n";
  122. unset($x[f("var_dim_unset")]);
  123. echo $y,"\n";
  124. // IS_VAR + conversion
  125. $z = $x->{f(7)};
  126. echo $y,"\n";
  127. $x->{f(8)} = 1;
  128. echo $y,"\n";
  129. ?>
  130. --EXPECT--
  131. const_get
  132. const_set
  133. const_call
  134. const_callstatic
  135. const_dim_get
  136. const_dim_set
  137. const_dim_isset
  138. const_dim_unset
  139. 1
  140. 2
  141. tmp_get
  142. tmp_set
  143. tmp_call
  144. tmp_dim_get
  145. tmp_dim_set
  146. tmp_dim_isset
  147. tmp_dim_unset
  148. 3
  149. 4
  150. cv_get
  151. cv_set
  152. cv_call
  153. cv_dim_get
  154. cv_dim_set
  155. cv_dim_isset
  156. cv_dim_unset
  157. 5
  158. 6
  159. var_get
  160. var_set
  161. var_call
  162. var_dim_get
  163. var_dim_set
  164. var_dim_isset
  165. var_dim_unset
  166. 7
  167. 8