In light of this statement and further testing in PHP4, I'm not sure if an object was being instantiated or not. It certainly didn't pipe up with an error.

Unfortunately, no (http://www.php.net/call_user_func):


"Object methods may also be invoked statically using this function by passing array($objectname, $methodname) to the function parameter."


However, my intention was to call call_user_func with the assumption that it would instantiate the class with the default constructor and any default arguments defined in the method signature of the constructor (in

You can do something like this with the Reflection API.


my example, none) and call an the specified instance method because ... wait for it ... it was defined as an instance method not a static method.

What was tripping me up was that neither the PHP4 manual description of this function nor Zeev's 3rd Edition of Core PHP5 indicate that any method of a class would be called statically even if it was not defined in the class as static. Basically, the change in behavior between PHP4 and PHP5 was very surprising to me.

IMHO, I believe that such behavior is fundamentally disconnected from
the perpetrated behavior of accepted practices.

ie, if I wanted a method to be called statically, I would have defined it statically.

ie, if the method signature of an object defines it as an instance method, I kind of expect it to ONLY ever be called or callabe as an instance method.

Ben Ramsey wrote:
<snip>

I would suggest that you read up on object-oriented programming and learn a little more about how things work.

You really need to do:

$test = new test_call_user_func();

to create the object. Then you can use $test to access the methods of that object.


Actually, the intention was to allow some tightly coupled delegation via SOAP. I know, tight coupling is asking for it on long term maintainence but I really didn't have a say in some of the architecture.

I haven't found an equivalent of Java's Class.forName(String

I'm not familiar with this Java class, but it appears to be doing Reflections. PHP5 has an actual Reflection_* classes to give you this functionality. I can even send you a small script about the new Reflection API if you like. However, this site should explain Reflection_Class:


http://sitten-polizei.de/php/reflection_api/docs/language.reflection.class.reflection_class.html

$class = Reflection_Class('SomeClass');
$method = $class->getMethod('Method');
$args = array($param1, $param2);
$method->invoke($class, $args);


Name_of_class_to_be_instantiated), so I thought call_user_func would suffice, instantiate a default version of my object, etc etc ...

Anyone else, back me up on this if I'm wrong.


I think that you and Curt are indeed correct about being able to use a $this only in an instance.

My issue is that I have not yet found anywhere were this change of behavior in PHP5 that [EMAIL PROTECTED] describes is documented.

If someone could point me to where we all could help with the documentation, that'd be great.

V

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to