Curt, Ben,

Thank you for your thoughts.

Actually, [EMAIL PROTECTED] addressed this via bugs at http://bugs.php.net/bug.php?id=28189 .

[27 Apr 11:47pm CEST] [EMAIL PROTECTED]
"The behavior that's new in PHP 5 isn't the inability to
call a method by call name instead of instance. It's
that if you do so, PHP treats it as a static method
call. When a static method is invoked in PHP 5, you
cannot reference $this because it no longer exists and
was never meaningful in the first place."

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.

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 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 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