static_properties_004.phpt 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. --TEST--
  2. Inherited static properties can be separated from their reference set.
  3. --FILE--
  4. <?php
  5. class C { public static $p = 'original'; }
  6. class D extends C { }
  7. class E extends D { }
  8. echo "\nInherited static properties refer to the same value across classes:\n";
  9. var_dump(C::$p, D::$p, E::$p);
  10. echo "\nChanging one changes all the others:\n";
  11. D::$p = 'changed.all';
  12. var_dump(C::$p, D::$p, E::$p);
  13. echo "\nBut because this is implemented using PHP references, the reference set can easily be split:\n";
  14. $ref = 'changed.one';
  15. D::$p =& $ref;
  16. var_dump(C::$p, D::$p, E::$p);
  17. ?>
  18. ==Done==
  19. --EXPECTF--
  20. Inherited static properties refer to the same value across classes:
  21. %unicode|string%(8) "original"
  22. %unicode|string%(8) "original"
  23. %unicode|string%(8) "original"
  24. Changing one changes all the others:
  25. %unicode|string%(11) "changed.all"
  26. %unicode|string%(11) "changed.all"
  27. %unicode|string%(11) "changed.all"
  28. But because this is implemented using PHP references, the reference set can easily be split:
  29. %unicode|string%(11) "changed.all"
  30. %unicode|string%(11) "changed.one"
  31. %unicode|string%(11) "changed.all"
  32. ==Done==