You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
4.0 KiB

  1. --TEST--
  2. SPL: ArrayObject: ensure a wrapped object's magic methods for property access are not invoked when manipulating the ArrayObject's elements using ->.
  3. --FILE--
  4. <?php
  5. class UsesMagic {
  6. public $a = 1;
  7. public $b = 2;
  8. public $c = 3;
  9. private $priv = 'secret';
  10. function __get($name) {
  11. $args = func_get_args();
  12. echo "In " . __METHOD__ . "(" . implode($args, ',') . ")\n";
  13. }
  14. function __set($name, $value) {
  15. $args = func_get_args();
  16. echo "In " . __METHOD__ . "(" . implode($args, ',') . ")\n";
  17. }
  18. function __isset($name) {
  19. $args = func_get_args();
  20. echo "In " . __METHOD__ . "(" . implode($args, ',') . ")\n";
  21. }
  22. function __unset($name) {
  23. $args = func_get_args();
  24. echo "In " . __METHOD__ . "(" . implode($args, ',') . ")\n";
  25. }
  26. }
  27. $obj = new UsesMagic;
  28. $ao = new ArrayObject($obj);
  29. echo "\n--> Write existent, non-existent and dynamic:\n";
  30. $ao->a = 'changed';
  31. $ao->dynamic = 'new';
  32. $ao->dynamic = 'new.changed';
  33. echo " Original wrapped object:\n";
  34. var_dump($obj);
  35. echo " Wrapping ArrayObject:\n";
  36. var_dump($ao);
  37. echo "\n--> Read existent, non-existent and dynamic:\n";
  38. var_dump($ao->a);
  39. var_dump($ao->nonexistent);
  40. var_dump($ao->dynamic);
  41. echo " Original wrapped object:\n";
  42. var_dump($obj);
  43. echo " Wrapping ArrayObject:\n";
  44. var_dump($ao);
  45. echo "\n--> isset existent, non-existent and dynamic:\n";
  46. var_dump(isset($ao->a));
  47. var_dump(isset($ao->nonexistent));
  48. var_dump(isset($ao->dynamic));
  49. echo " Original wrapped object:\n";
  50. var_dump($obj);
  51. echo " Wrapping ArrayObject:\n";
  52. var_dump($ao);
  53. echo "\n--> Unset existent, non-existent and dynamic:\n";
  54. unset($ao->a);
  55. unset($ao->nonexistent);
  56. unset($ao->dynamic);
  57. echo " Original wrapped object:\n";
  58. var_dump($obj);
  59. echo " Wrapping ArrayObject:\n";
  60. var_dump($ao);
  61. ?>
  62. --EXPECTF--
  63. --> Write existent, non-existent and dynamic:
  64. Original wrapped object:
  65. object(UsesMagic)#1 (4) {
  66. [u"a"]=>
  67. int(1)
  68. [u"b"]=>
  69. int(2)
  70. [u"c"]=>
  71. int(3)
  72. [u"priv":u"UsesMagic":private]=>
  73. unicode(6) "secret"
  74. }
  75. Wrapping ArrayObject:
  76. object(ArrayObject)#2 (3) {
  77. [u"a"]=>
  78. unicode(7) "changed"
  79. [u"dynamic"]=>
  80. unicode(11) "new.changed"
  81. [u"storage":u"ArrayObject":private]=>
  82. object(UsesMagic)#1 (4) {
  83. [u"a"]=>
  84. int(1)
  85. [u"b"]=>
  86. int(2)
  87. [u"c"]=>
  88. int(3)
  89. [u"priv":u"UsesMagic":private]=>
  90. unicode(6) "secret"
  91. }
  92. }
  93. --> Read existent, non-existent and dynamic:
  94. unicode(7) "changed"
  95. Notice: Undefined property: ArrayObject::$nonexistent in %s on line 42
  96. NULL
  97. unicode(11) "new.changed"
  98. Original wrapped object:
  99. object(UsesMagic)#1 (4) {
  100. [u"a"]=>
  101. int(1)
  102. [u"b"]=>
  103. int(2)
  104. [u"c"]=>
  105. int(3)
  106. [u"priv":u"UsesMagic":private]=>
  107. unicode(6) "secret"
  108. }
  109. Wrapping ArrayObject:
  110. object(ArrayObject)#2 (3) {
  111. [u"a"]=>
  112. unicode(7) "changed"
  113. [u"dynamic"]=>
  114. unicode(11) "new.changed"
  115. [u"storage":u"ArrayObject":private]=>
  116. object(UsesMagic)#1 (4) {
  117. [u"a"]=>
  118. int(1)
  119. [u"b"]=>
  120. int(2)
  121. [u"c"]=>
  122. int(3)
  123. [u"priv":u"UsesMagic":private]=>
  124. unicode(6) "secret"
  125. }
  126. }
  127. --> isset existent, non-existent and dynamic:
  128. bool(true)
  129. bool(false)
  130. bool(true)
  131. Original wrapped object:
  132. object(UsesMagic)#1 (4) {
  133. [u"a"]=>
  134. int(1)
  135. [u"b"]=>
  136. int(2)
  137. [u"c"]=>
  138. int(3)
  139. [u"priv":u"UsesMagic":private]=>
  140. unicode(6) "secret"
  141. }
  142. Wrapping ArrayObject:
  143. object(ArrayObject)#2 (3) {
  144. [u"a"]=>
  145. unicode(7) "changed"
  146. [u"dynamic"]=>
  147. unicode(11) "new.changed"
  148. [u"storage":u"ArrayObject":private]=>
  149. object(UsesMagic)#1 (4) {
  150. [u"a"]=>
  151. int(1)
  152. [u"b"]=>
  153. int(2)
  154. [u"c"]=>
  155. int(3)
  156. [u"priv":u"UsesMagic":private]=>
  157. unicode(6) "secret"
  158. }
  159. }
  160. --> Unset existent, non-existent and dynamic:
  161. Original wrapped object:
  162. object(UsesMagic)#1 (4) {
  163. [u"a"]=>
  164. int(1)
  165. [u"b"]=>
  166. int(2)
  167. [u"c"]=>
  168. int(3)
  169. [u"priv":u"UsesMagic":private]=>
  170. unicode(6) "secret"
  171. }
  172. Wrapping ArrayObject:
  173. object(ArrayObject)#2 (1) {
  174. [u"storage":u"ArrayObject":private]=>
  175. object(UsesMagic)#1 (4) {
  176. [u"a"]=>
  177. int(1)
  178. [u"b"]=>
  179. int(2)
  180. [u"c"]=>
  181. int(3)
  182. [u"priv":u"UsesMagic":private]=>
  183. unicode(6) "secret"
  184. }
  185. }