<?php
class LeClass
{
public $name;
public $surname;
public $email;
}
class LeTestClass
{
public function leFun($obj)
{
foreach ($obj as $property => $value) {
//var_dump($property);
switch ($property) {
case "name":
case "surname":
$obj->$property = 'Василий';
//var_dump($obj->$property);
break;
case 'email':
$obj->$property = 'Иван';
break;
//default:
// $obj->$property = 'Иван';
}
}
}
}
$test = new LeTestClass;
$obj = new LeClass;
$test->leFun($obj);
PD9waHAKY2xhc3MgTGVDbGFzcwp7CiAgICBwdWJsaWMgJG5hbWU7CiAgICBwdWJsaWMgJHN1cm5hbWU7CiAgICBwdWJsaWMgJGVtYWlsOwoKfQoKY2xhc3MgTGVUZXN0Q2xhc3MKewogICAgcHVibGljIGZ1bmN0aW9uIGxlRnVuKCRvYmopCiAgICB7CiAgICAgICAgZm9yZWFjaCAoJG9iaiBhcyAkcHJvcGVydHkgPT4gJHZhbHVlKSB7CiAgICAgICAgCS8vdmFyX2R1bXAoJHByb3BlcnR5KTsKICAgICAgICAgICAgc3dpdGNoICgkcHJvcGVydHkpIHsKICAgICAgICAgICAgICAgIGNhc2UgIm5hbWUiOgogICAgICAgICAgICAgICAgY2FzZSAic3VybmFtZSI6CiAgICAgICAgICAgICAgICAgICAgJG9iai0+JHByb3BlcnR5ID0gJ9CS0LDRgdC40LvQuNC5JzsKICAgICAgICAgICAgICAgICAgICAvL3Zhcl9kdW1wKCRvYmotPiRwcm9wZXJ0eSk7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBjYXNlICdlbWFpbCc6CiAgICAgICAgICAgICAgICAJJG9iai0+JHByb3BlcnR5ID0gJ9CY0LLQsNC9JzsKICAgICAgICAgICAgICAgIAlicmVhazsKICAgICAgICAgICAgICAgIC8vZGVmYXVsdDoKICAgICAgICAgICAgICAgIC8vCSRvYmotPiRwcm9wZXJ0eSA9ICfQmNCy0LDQvSc7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyX2R1bXAoJG9iai0+JHByb3BlcnR5KTsKICAgICAgICB9CiAgICB9Cn0KCiR0ZXN0ID0gbmV3IExlVGVzdENsYXNzOwokb2JqID0gbmV3IExlQ2xhc3M7CiR0ZXN0LT5sZUZ1bigkb2JqKTsKdmFyX2R1bXAoJG9iaik7