开发者

PHP call static workaround for PHP 5.2

Is there ar开发者_运维问答e way to get __callStatic, or similar, functionality in PHP 5.2?

I'm finishing a PHP Framework and need to use this functionality for a Database ORM class. So for example you can use the code below to get data from column 2 and column 4 of the database table i.e. by declaring methods dynamically according to what you want (like rails I guess).

Class::find_by_col2_or_col4();

I have already done this in PHP 5.3 and it works perfectly, but I'm trying to do the same for those using PHP 5.2.

Or is there some other way to retrieve the name of the static method and arguments using PHP 5.2?

Thanks.


Not in a static capacity. Technically speaking Rails, CakePHP, etc don't call these types of dynamic methods statically. Not to get in a philosophical debate, but if backward compatibility is a requirement, you could shift your paradigm and use __call(). In which case you would call with an object like ModelObject->find_by_col2_or_col4. Of course I understand that's probably not what you wanted to hear.

It's PHP, there's probably some kind of way to hack it, but I don't believe a native method exists.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜