dereferencing_001.phpt 502 B

123456789101112131415161718192021222324252627282930313233
  1. --TEST--
  2. ZE2 dereferencing of objects from methods
  3. --FILE--
  4. <?php
  5. class Name {
  6. function __construct($_name) {
  7. $this->name = $_name;
  8. }
  9. function display() {
  10. echo $this->name . "\n";
  11. }
  12. }
  13. class Person {
  14. private $name;
  15. function __construct($_name, $_address) {
  16. $this->name = new Name($_name);
  17. }
  18. function getName() {
  19. return $this->name;
  20. }
  21. }
  22. $person = new Person("John", "New York");
  23. $person->getName()->display();
  24. ?>
  25. --EXPECT--
  26. John