开发者

Is there a PHP configuration setting that would prevent use of variable before it's set?

I have the following code:

<?php 
  if ($foo) {
    echo $foo;
  }
 ?>

However, my page is throwing a 500 internal server error (I know this gener开发者_StackOverflow中文版ally means there's an error being logged and the page is aborting prematurely) I do not have access to the error log (as the host is logging to syslog).

I can fix it by doing the following:

<?php 
  if (isset($foo) && $foo) {
    echo $foo;
  }
 ?>

but that's not my question. Is there a server setting that would kill a page attempting to use an unset variable? AFAIK, it only logs a 'Notice', which is normally not enough to kill the page.

Here is the first bit of the phpinfo() output (disclaimer: I have no Windows + FastCGI setup experience)

Is there a PHP configuration setting that would prevent use of variable before it's set?

Update I added a custom error handler and simply output the $errno and $errstr. As expected, it was an E_NOTICE (8) with message 'Undefined variable'. I'm guessing the 500 internal error has something to do with how it's logging to the syslog.


Implement a custom error handler and you can do anything you'd like (mostly)!


In my experience 500th errors are usually caused by infinite loops ( either directly in code , or because of unending redirect ). Or it has something to do with display_errors setting on php.ini file.

If you have no access to server logs, i would recommend for you to use VirtualBox ( or some other virtualization tool ) and set up identical server environment in VM, and then see what exactly you get in the logs.

P.S. why cant you host your page on a normal NIX server with an up-to-date PHP version ?!


I dont know of any setting that would do that... I suspect something else is goign wrong after that, perhaps because the variable isnt set. Your best bet here is probably to do as David suggest and make a quick custom error handler so you can get some reporting on what is actually happening.

As an aside your host should be giving you some kind of access to the error logs even if he wants to send errors to syslog . I dont think ive ever been on a host that hasnt made error logs available. Id recommend switching hosts if you can. This is kind of something everyone expects...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜