FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » What could be causing this "Invalid callback" warning?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
What could be causing this "Invalid callback" warning? [message #170910] Wed, 08 December 2010 03:33 Go to next message
Roy Smith is currently offline  Roy Smith
Messages: 11
Registered: November 2010
Karma: 0
Junior Member
We're setting our own error handler by calling:

set_error_handler(array('Amie_ResponseHandler','errorHandler'));

this seems work work fine everywhere, except in one case where we do

require_once("HTTP/Request.php");

which loads the PEAR HTTP_Request class. That file generates some
deprecation warnings when it's loaded. I understand why we're getting
the deprecation warnings, but the weird thing is we're also getting
complains about our error handler being an invalid callback:

[07-Dec-2010 21:48:53] PHP Deprecated: Assigning the return value of
new by reference is deprecated in /usr/share/php/HTTP/Request.php on
line 402
[07-Dec-2010 21:48:53] PHP Warning: Invalid callback
Amie_ResponseHandler::errorHandler, class 'Amie_ResponseHandler' not
found in /usr/share/php/HTTP/Request.php on line 722

this makes no sense. I *know* the Amie_ResponseHandler class exists,
and has already been loaded. I can watch our autoloader code load the
file, and set_error_hander() call shown above is in a static method of
that class; the fact that the error handler was registered at all
pretty much proves the class was loaded.

I'm stumped what might be going on. Any clues where to look to figure
this out?

We're running:

PHP 5.3.2-1ubuntu4.5 with Suhosin-Patch (cli) (built: Sep 17 2010
13:49:46)
Re: What could be causing this "Invalid callback" warning? [message #170911 is a reply to message #170910] Wed, 08 December 2010 03:43 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 12/7/2010 10:33 PM, Roy Smith wrote:
> We're setting our own error handler by calling:
>
> set_error_handler(array('Amie_ResponseHandler','errorHandler'));
>
> this seems work work fine everywhere, except in one case where we do
>
> require_once("HTTP/Request.php");
>
> which loads the PEAR HTTP_Request class. That file generates some
> deprecation warnings when it's loaded. I understand why we're getting
> the deprecation warnings, but the weird thing is we're also getting
> complains about our error handler being an invalid callback:
>
> [07-Dec-2010 21:48:53] PHP Deprecated: Assigning the return value of
> new by reference is deprecated in /usr/share/php/HTTP/Request.php on
> line 402
> [07-Dec-2010 21:48:53] PHP Warning: Invalid callback
> Amie_ResponseHandler::errorHandler, class 'Amie_ResponseHandler' not
> found in /usr/share/php/HTTP/Request.php on line 722
>
> this makes no sense. I *know* the Amie_ResponseHandler class exists,
> and has already been loaded. I can watch our autoloader code load the
> file, and set_error_hander() call shown above is in a static method of
> that class; the fact that the error handler was registered at all
> pretty much proves the class was loaded.
>
> I'm stumped what might be going on. Any clues where to look to figure
> this out?
>
> We're running:
>
> PHP 5.3.2-1ubuntu4.5 with Suhosin-Patch (cli) (built: Sep 17 2010
> 13:49:46)
>

The first element of the array you're passing must be an object of the
error handler, not a string with the name of the class.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: What could be causing this "Invalid callback" warning? [message #170912 is a reply to message #170911] Wed, 08 December 2010 03:55 Go to previous messageGo to next message
Roy Smith is currently offline  Roy Smith
Messages: 11
Registered: November 2010
Karma: 0
Junior Member
> The first element of the array you're passing must be an object of the
> error handler, not a string with the name of the class.

This is kind of confusing. The docs (http://us3.php.net/manual/en/
function.set-error-handler.php) say (in the changelog section):

"Instead of a function name, an array containing an object reference
and a method name can also be supplied as the error_handler"

which agrees with what you say, but on that same page, there's a
comment from "jonbarnett at gmail dot com" which says:

---------------------------------------
The proper way to set a callback for a static class function is:

array("Classname", "functionname")

The class name is a string. If you don't quote the string, PHP treats
it as a barestring and triggers a notice.
---------------------------------------

Is the comment just wrong?
Re: What could be causing this "Invalid callback" warning? [message #170913 is a reply to message #170912] Wed, 08 December 2010 04:08 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 12/7/2010 10:55 PM, Roy Smith wrote:
>> The first element of the array you're passing must be an object of the
>> error handler, not a string with the name of the class.
>
> This is kind of confusing. The docs (http://us3.php.net/manual/en/
> function.set-error-handler.php) say (in the changelog section):
>
> "Instead of a function name, an array containing an object reference
> and a method name can also be supplied as the error_handler"
>
> which agrees with what you say, but on that same page, there's a
> comment from "jonbarnett at gmail dot com" which says:
>
> ---------------------------------------
> The proper way to set a callback for a static class function is:
>
> array("Classname", "functionname")
>
> The class name is a string. If you don't quote the string, PHP treats
> it as a barestring and triggers a notice.
> ---------------------------------------
>
> Is the comment just wrong?

No, that's for a STATIC function. You are not calling a static member
of the class, so an object is required (which is what your message is
telling you).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: What could be causing this "Invalid callback" warning? [message #170914 is a reply to message #170913] Wed, 08 December 2010 05:11 Go to previous messageGo to next message
Roy Smith is currently offline  Roy Smith
Messages: 11
Registered: November 2010
Karma: 0
Junior Member
On Dec 7, 11:08 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> No, that's for a STATIC function.  You are not calling a static member
> of the class, so an object is required (which is what your message is
> telling you).

Um, is there some specific reason you think
Amie_ResponseHandler::errorHandler() is not static? It's declared:

public static function errorHandler($severity,$msg,$filename,
$linenum) {
... }
Re: What could be causing this "Invalid callback" warning? [message #170926 is a reply to message #170914] Wed, 08 December 2010 22:32 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 12/8/2010 12:11 AM, Roy Smith wrote:
> On Dec 7, 11:08 pm, Jerry Stuckle<jstuck...@attglobal.net> wrote:
>> No, that's for a STATIC function. You are not calling a static member
>> of the class, so an object is required (which is what your message is
>> telling you).
>
> Um, is there some specific reason you think
> Amie_ResponseHandler::errorHandler() is not static? It's declared:
>
> public static function errorHandler($severity,$msg,$filename,
> $linenum) {
> ... }
>

Sorry, I should have read the message more closely. I shouldn't try to
do this when I'm tired :)

Are you sure the class is being loaded? Just using the class name as a
string in the set_error_handler() call doesn't necessarily check that
the class exists at that time.

What happens if you specifically load the class with require_once()
before calling set_error_handler()? Or what happens if you do a

$hdlr = new Amnie_ResponseHandler();

before registering the class?

I don't use the PEAR HTTP_Request class; it's way back level (as you
found), and everything in the class is available anyway. Just never
found a need for it. So I can't say how it works when you're loading
that code.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Try to write php code for this ..
Next Topic: Session Handling for multiple languages, permission denied
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 06:27:43 GMT 2024

Total time taken to generate the page: 0.02450 seconds