Comments By: Aaron Davis
-
Nice article. I just have one beef, regarding number 1. The Reflection API is pretty cool, but the example you give as to why you should use it is terrible. You say that "call_user_func_array(array('TestCallFunc', '__construct'), array('hello', 'sir'))" doesn't work, and you are right. But if you think about it for a moment, it should be obvious why. There are three ways to call call_user_func_array: 1. When you call it with a function name as the argument it calls that function. Basically eval()ing "function_name([expanded $args])" 2. When you call it with an array of an object, and a method name, it calls the method on the object. This is like eval()ing $obj->function_name() 3. When you call it with an array of a class name, and a method name, it statically calls the method for that class (although, it should work even without the static keyword on the method, as long as the method doesn't use $this). This is like eval()ing "ClassName::method_name()" If you think about it for a second, the example shouldn't work, since it is equivalent to "TestCallFunc::__construct()," which is meaningless. __construct is really an initializer, not a constructor, anyway; it doesn't get called until after the object is created. Your example would make sense if you replaced "__construct" with "new" but that still doesn't work because "new" is an operator in PHP, not a class method.posted on Aug 23, 2007 at 9:16pm | context