Guest User

Untitled

a guest
Oct 4th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. <?php
  2.  
  3. class Person
  4. {
  5. protected $name;
  6.  
  7. public function __construct(string $name)
  8. {
  9. $this->name = $name;
  10. }
  11.  
  12. public function __get($prop)
  13. {
  14. return $this->$prop;
  15. }
  16.  
  17. public function __isset($prop) : bool
  18. {
  19. return isset($this->$prop);
  20. }
  21. }
  22.  
  23. $people = [
  24. new Person('Fred'),
  25. new Person('Jane'),
  26. new Person('John'),
  27. ];
  28.  
  29.  
  30. print_r(array_column($people, 'name'));
Add Comment
Please, Sign In to add comment