class A {
$props = array('prop1', 'prop2', 'prop3');
}
How to convert above defined array into class properties ? The final result would be..
class A {
$props = array('prop1', 'prop2', 'prop3');
public $prop1;
public $prop2;
public $prop3;
}
I have tried this so far :
public function convert(){
foreach ($this->props as $prop) {
$this->prop;
}
}
Looks bit ugly as I am new to php
You may use php magic methods
__getand__setlike this (study when and how are they invoked before implementing):And you would use it as normal properties:
It would be also nice if you would implement:
public function __isset($key){}public function __unset($key){}so you’ll have consistent and complete class.