arrayObject_setFlags_basic1.phpt 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. --TEST--
  2. SPL: ArrayObject::setFlags basic usage with ArrayObject::ARRAY_AS_PROPS. Currently fails on php.net due to bug 45622.
  3. --FILE--
  4. <?php
  5. class C extends ArrayObject {
  6. public $p = 'object property';
  7. }
  8. function access_p($ao) {
  9. // isset
  10. var_dump(isset($ao->p));
  11. // read
  12. var_dump($ao->p);
  13. // write
  14. $ao->p = $ao->p . '.changed';
  15. var_dump($ao->p);
  16. }
  17. $ao = new C(array('p'=>'array element'));
  18. $ao->setFlags(ArrayObject::ARRAY_AS_PROPS);
  19. echo "\n--> Access the real property:\n";
  20. access_p($ao);
  21. echo "\n--> Remove the real property and access the array element:\n";
  22. unset($ao->p);
  23. access_p($ao);
  24. echo "\n--> Remove the array element and try access again:\n";
  25. unset($ao->p);
  26. access_p($ao);
  27. ?>
  28. --EXPECTF--
  29. --> Access the real property:
  30. bool(true)
  31. string(15) "object property"
  32. string(23) "object property.changed"
  33. --> Remove the real property and access the array element:
  34. bool(true)
  35. string(13) "array element"
  36. string(21) "array element.changed"
  37. --> Remove the array element and try access again:
  38. bool(false)
  39. Warning: Undefined array key "p" in %s on line %d
  40. NULL
  41. Warning: Undefined array key "p" in %s on line %d
  42. string(8) ".changed"