0

well i do have a small PHP class with some properties on it

class A{
 public $pro1 = "abc";
 public $pro2 = "def";

 public function __construct(){}
}
$a = new A();

now i want to change $a 's properties by using an associative array, somewhat like this

$modpro = array("pro1"=>"123","pro2"=>"456");
modify_object($a,$modpro);

is this possible?

NOTE: i don't have the right to modify the class and my problem is my senior is always modifying the class. I'm thinking of much dynamic way of handling the changes the class without setting many methods for modifying the object properties

1 Answer 1

2
$modpro = array('pro1' => '123', 'pro2' => '456');
foreach ($modpro as $prop => $value) {
    $a->$prop = $value;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.