NogDog;10891011 wrote:I'm admittedly having a difficult time why you would want to simply ignore the defined interface of a class. It seems to run contrary to the general precepts of encapsulation in OOP. So my first suggestion would be to re-think the underlying design logic that has led you to this situation and consider whether there is a "better" means to your ends. If not, all I can think of is a sort of wrapper object.
Thank you for the response. I had to set aside this project for a little while, which is why I haven't responded quickly, but now I'm looking at it again.
For the project I'm working on, the only thing I can pass to PHP is a set of parameters in text format. It's sort of like having a user submit form data and trying to use that form data to call a class. That's not exactly the case, but it's close enough for my explanation here. The code example you gave earlier is still missing the critical part that I need: the ability to create a new object with an unknown number of parameters. In your code, you wrote:
$test = new Wrapper(new Example('bar'), $params);
Notice that you are supplying only one parameter ('bar') to the new object upon creating it. That's exactly the part that I need to fix. Somehow, I need to be able to create the object no matter how many parameters it requires. For example, the same wrapper should be able to accommodate all of these new objects:
new Example2('bar', 'bar2', 'bar3')
new Example3('bar', 'bar2')
new Example4('bar', 'bar2', 'bar3', 'bar4', 'bar5', 'bar6')
That's the part that I'm having trouble figuring out.