fork(1) download
  1. <?php
  2. class LeClass
  3. {
  4. public $name;
  5. public $surname;
  6. public $email;
  7.  
  8. }
  9.  
  10. class LeTestClass
  11. {
  12. public function leFun($obj)
  13. {
  14. foreach ($obj as $property => $value) {
  15. //var_dump($property);
  16. switch ($property) {
  17. case "name":
  18. case "surname":
  19. $obj->$property = 'Василий';
  20. //var_dump($obj->$property);
  21. break;
  22. case 'email':
  23. $obj->$property = 'Иван';
  24. break;
  25. //default:
  26. // $obj->$property = 'Иван';
  27. }
  28. var_dump($obj->$property);
  29. }
  30. }
  31. }
  32.  
  33. $test = new LeTestClass;
  34. $obj = new LeClass;
  35. $test->leFun($obj);
  36. var_dump($obj);
Success #stdin #stdout 0.02s 24448KB
stdin
Standard input is empty
stdout
string(14) "Василий"
string(14) "Василий"
string(8) "Иван"
object(LeClass)#2 (3) {
  ["name"]=>
  string(14) "Василий"
  ["surname"]=>
  string(14) "Василий"
  ["email"]=>
  string(8) "Иван"
}