fork(1) download
  1. <?php
  2.  
  3. trait HasGettersAndSetters {
  4. function __get($name) {
  5. $method = "get_$name";
  6. return $this->$method();
  7. }
  8.  
  9. function __set($name, $value) {
  10. $method = "set_$name";
  11. return $this->$method($value);
  12. }
  13. }
  14.  
  15. class Order {
  16. use HasGettersAndSetters;
  17.  
  18. private function get_customer() {
  19. return 42;
  20. }
  21. }
  22.  
  23. $order = new Order();
  24. echo $order->customer;
  25.  
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
42