4

So I have hosting that refuses to update to PHP 5.3 (which is annoying but fine at the same time; I'm flexible), but the only thing that is really ticking me off is not having __callStatic available.

I have modules loaded that I'm wanting to consolidate down to a single class (i.e. have a class that loads modules, and then accesses those modules' functions through calls to the main class' __callStatic method), but when I uploaded from a local testing server to my server, obviously the __callStatic method didn't work.

Is there an alternative that is still static? I like the clean code look for the double colon (i.e. registry::some_func()) instead of $registry->some_func().

Another down-side to this is that I'm now forced to use the global keyword within functions (which by my own preference is very, very messy).

The code was also extremely fast using static methods instead of non-static methods, and in-turn much more clean.

Also: I've thought about writing the __callStatic method as usual with the 5.2 and then calling the methods explicitly, for example registry::__callStatic("some_func"), array("val", "val2", "val3") and keeping things simpler that way, even being easier to migrate when they do upgrade to 5.3. Thoughts on this method?

Thanks!

4

1 回答 1

1

如果想要这样做的唯一原因是双冒号的速度和主观吸引力,我会说成长以欣赏破折号的道,冒险并使用对象实例。你所说的“干净的代码外观”就像锤子裤......一年酷,几年后当你年纪大了,更聪明了就不那么酷了。__callStatic()(IMVHO) 充其量只是一种不必要的次要便利,而在最坏的情况下,它是糟糕的类设计的一种解决方法。:)

于 2011-01-06T22:41:52.693 回答