I'm wondering if its possible to add new class data members at run-time in PHP?
Yes.
$prop = 'newname';
$obj->$prop = 42;
will do the same thing as:
$obj->newname = 42;
Either one will add "newname" as a property in $obj if it does not yet exist.
It is. You can add public members are run time with no additional code, and can affect protected/private members using the magical overloading methods __get() / __set(). See here for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With