开发者

string matching for a magic __call method

I have a set of methods named like getThing($what, $extra_args) (get is always present in the name)

...and besides the normal way of calling them, I also want to be able to call them like:

  • getWhatThing() => return getThing($what, $extra_args);

  • WhatThing() => echo getThing($what, $extra_args);

  • Thing('what') => echo getThing('what', $extra_args);

  • if all these fail throw the Method doesn't exist error...

How c开发者_StackOverflowan I do this from within __call() ? I know I should avoid magic methods, but I want to make life easier for the people who will use my API :)

Thanks


What you are asking is a non sense..
All your methods should just return $var.

At that point if you want to echo it you need to excplicty do:

echo getThing();


The code in this comment on PHP.net's documentation for __call should be a good starting point for you, but you'll need to add more matches to the switch section.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜