Weird error with division by zero

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
oxez
Forum Newbie
Posts: 6
Joined: Thu Aug 03, 2006 11:52 pm

Weird error with division by zero

Post by oxez »

Ok, so bascically what I'm currently doing is an error handler. I've created a Debugger class, and used set_error_handler() to use that class.

So, to test this, I've tried a mysql_connect() with wrong infos, my Debugger caught that, and displayed it the way I wanted.

I tried this explicetly (there are no variables involved in this math): echo 4/0;

On my windows server, my error handler catches it. On my linux server, it works. On my friend's server, it also works. But on my current webhost, it just doesn't work..

I get an error like: "Warning: Division by zero in Unknown on line 0" . Notice the "Unknown on line 0" part. Weird? Yes it is...

So, I tried that 4/0 thing without my Debugger class on my own machine as well, and I get what I'm supposed to get: "Warning: Division by zero in /media/stuff/www/zeal/index.php on line 14" . There are no "Unknown on line 0" there..

After all those tests, I tried to compare php.ini files on every server, and they all look the same. But, on my webhost, Zend Optimiser was installed. Maybe the optimiser could cause this weird thing, so I installed Zend Optimiser (tried versions 2 and 3) on my linux machine, and my code was still working. No success again.

So I'm asking for help here, I have no idea how to fix that, and google isn't being useful on that one..

Note: All the servers I tried my code run are running PHP 5.1.4 (latest), on Apache. Please also note that I used the same code everywhere (in fact, I use SVN, so I just had to checkout my repository).

Thanks in advance!
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

You may want to post your code.
oxez
Forum Newbie
Posts: 6
Joined: Thu Aug 03, 2006 11:52 pm

Post by oxez »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Oh ok.

Code: Select all

<?php

require("modules/ZealObject.php");
require("modules/Debugger.php");
require("modules/HTMLDocument.php");

$document = new HTMLDocument();
$document->addStyleSheet("style.css");
$document->addStyleSheet("print.css", "print");
$document->addJavaScript("javascript.js");
$document->setJavascriptCode("enableButton()");
$document->display();
mysql_connect("localhost", "allo", "");
echo 4 / 0;
Debugger::generateOutput();
?>
But, the only interesting part is: echo 4 / 0;. That's where I get different error warnings on my webhost..


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Try turning display_errors off.
oxez
Forum Newbie
Posts: 6
Joined: Thu Aug 03, 2006 11:52 pm

Post by oxez »

ini_set("display_errors", "off"); didn't do anything (I don't have write permission on php.ini).

I still get the "Warning: Division by zero in Unknown on line 0" warning...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

ini_set() will not affect it, the error happens during initial parsing. You can however change it with .htaccess files.
oxez
Forum Newbie
Posts: 6
Joined: Thu Aug 03, 2006 11:52 pm

Post by oxez »

I just tried "php_flag display_errors off", same result...
oxez
Forum Newbie
Posts: 6
Joined: Thu Aug 03, 2006 11:52 pm

Post by oxez »

Any other ideas ? (I'm been struggling with this one for days, I really start to think I won't be able to do much about it.. I talked to my webhost, and he's also investigating on his side.)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Are all of your servers using the same extensions? There is a chance that a math extension maybe processing that line as math instead of a string. Another thing try would be to wrap it in quotes as a string or type cast to a string.
oxez
Forum Newbie
Posts: 6
Joined: Thu Aug 03, 2006 11:52 pm

Post by oxez »

Everah:

I looked in php.ini (and in phpinfo() to be sure) for *math*, and the settings were identical. But, adding (string) makes it work. My error handler now catches it! At least I now know the solution, but hm.. there must be a way to avoid adding (string) each time...

Thanks!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

That is an odd one. I am really not sure how three of four treat it one way and the one treats in another way. If you come up with something on this, post back so we can all get a little closer to figuring out PHP.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Do...

Code: Select all

$test = 4 / 0; // or
echo (4 / 0);
...cause the same problem?

Also you could try explicitly setting the second param on set_error_handler:

Code: Select all

mixed set_error_handler ( callback error_handler [, int error_types] )
Post Reply