First, I would suggest NOT returning if the prefix or property variables are not set. This will make debugging VERY difficult. Instead, replace return; on throw new BadMethodCallException('Method Does Not Exist: '.$method);
Secondly, doesn't that defeat the point of protected variables? It allows you to read and write all properties without any verification. If you intend to do this, you can also make them publicly available.
I personally consider $foo->bar = 'baz'; more readable than $foo->setBar('baz'); . Not because it is βeasierβ to understand, but because the second is too detailed.
Personally, I suggest doing __get and __set and adding validation. The whole point of protecting variables is trust (so you can trust the settings). Of course, you can use reflection or subclassification to change them, but I usually assume that if someone goes this far, they deserve any unintentional conspiracies if they ruined the variable.
And keep in mind that if you use some kind of magic method, you will need to add documentation elements if you want your ID environment to tell you methods / variables ...
EDIT:
And don't forget that if you declare __get / __set , you can override them in child classes. Therefore, if a child declares new variables, you can process them there, and then call parent::__get to handle the default variables. Therefore, do not use the array only so that you have one method for all children. Do validation for members you know about and let your children do their own validation ...
source share