PHP5 has a "magic method" __call()
that can be defined on any class that is invoked when an undefined method is called -- it is roughly equivalent to Ruby's method_missing
or Perl's AUTOLOAD
. Is it possible to do something like this in older versions of PHP?
views:
496answers:
3
A:
I recall using it, and a little bit of googling suggests that
function __call($method_name, $parameters, &$return)
{
$return_value = "You called ${method_name}!";
}
as a member function will do the job.
Adam Wright
2008-09-16 20:10:23
I suspect jes5199 was thinking of the __call method when he asked if anyone knew anything like the __call method... I think "in PHP4" was the critical part of the question.
reefnet_alex
2008-09-16 20:13:58
Yes, and I was referring to PHP4. Note the change in signature, which changed in 5.
Adam Wright
2008-09-16 23:31:38
ah, it looks like you're right, but also (a vital bit that I was missing), you must use the overload("ClassName") function to *enable* the __call method.
jes5199
2008-09-21 23:59:09
+1
A:
This article, Using Method Call Overloading in PHP 4 over on DevShed might help.
Novaktually
2008-09-16 20:11:11
+2
A:
The most important bit that I was missing was that __call
exists in PHP4, but you must enable it on a per-class basis by calling overload()
, as seen in php docs here .
Unfortunately, the __call() function signatures are different between PHP4 and PHP5, and there does not seem to be a way to make an implementation that will run in both.
jes5199
2008-09-22 00:02:50