Well if the controller exists in the global scope then you can always declare it "global" at the start of the function call.
Because of the monkey patching terminology, I assume you don't want to modify the controller's code? If you don't mind... then you could make the controller a singleton or you could declare the member function static.
I don't really see why you are worried about the extra object. If your really worried you can declare unset($controller) but PHP will garbage collect at the end of a function's execution anyway, at which point the extra object will be out of scope.
Edit:
Was just wondering but shouldn't the controller be delegating the validation_function to the validation object, rather than the validation object requesting it from the controller? If you do it that way, then that should solve your problem. If you can't touch the original controller code, you could extend it.
Edit #2:
There seems to be a few changes to the garbage collection and an issue with objects being picked up by the garbage collector. I'll go have a look into it and report back.
cont.
The garbage collector definitely does the rounds at the end of a method or function call (in PHP 5.2.13). Calling unset just before the function ends would be a waste of processor time. As for the issue with objects, destroying child objects doesn't remove their parents (whether you use direct reference or inheritance). Tis Strange.
Last edited by Alan; 30 Mar 2010 at 04:07 PM.
Reason: spelling mistake (confused a monkey with a duck) :(
“The best thing about a boolean is even if you are wrong, you are only off by a bit.”