attributes.php 693 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. class Foo {
  3. private static $hash;
  4. protected static function ensure_hash() {
  5. if (!isset(self::$hash)) {
  6. self::$hash = spl_object_hash(self);
  7. echo "Set hash to " . print_r(self::$hash, TRUE) . "\n";
  8. }
  9. }
  10. protected static function ensure_key($name) {
  11. $key = self::hash . '_' . $name;
  12. if (!property_exists(__CLASS__, $key)) {
  13. self::${$key} = NULL;
  14. }
  15. }
  16. public static function attr_reader() {
  17. $args = func_get_args();
  18. if (!empty($args)) {
  19. self::ensure_hash();
  20. foreach ($args as $name) {
  21. self::ensure_key($name);
  22. }
  23. }
  24. }
  25. public function attr_writer() {
  26. }
  27. public function attr_accessor() {
  28. }
  29. }