option 'explicit' for php
-
Hi, I'm having major problems with erratic php behavior. I think it's something to do with the server, though I'm not sure. It is incomprehensible in a way that C++ or VB could never be: the same code will work and then not work even though no inputs or context have changed. I need to get a handle on this. A step in the right direction would be to get more information out of the server. Is there an "explicit" or "strict" option in php? I've searched for it here, and on the general Internet and haven't found it. I could try to explain the behavior but no one would believe me anyway. It is pretty much as if there were a "ghost in the machine" making arbitrary decisions as to when the code will work. Jeff
-
Hi, I'm having major problems with erratic php behavior. I think it's something to do with the server, though I'm not sure. It is incomprehensible in a way that C++ or VB could never be: the same code will work and then not work even though no inputs or context have changed. I need to get a handle on this. A step in the right direction would be to get more information out of the server. Is there an "explicit" or "strict" option in php? I've searched for it here, and on the general Internet and haven't found it. I could try to explain the behavior but no one would believe me anyway. It is pretty much as if there were a "ghost in the machine" making arbitrary decisions as to when the code will work. Jeff
-
Hi, I'm having major problems with erratic php behavior. I think it's something to do with the server, though I'm not sure. It is incomprehensible in a way that C++ or VB could never be: the same code will work and then not work even though no inputs or context have changed. I need to get a handle on this. A step in the right direction would be to get more information out of the server. Is there an "explicit" or "strict" option in php? I've searched for it here, and on the general Internet and haven't found it. I could try to explain the behavior but no one would believe me anyway. It is pretty much as if there were a "ghost in the machine" making arbitrary decisions as to when the code will work. Jeff
Jeffrey Webster wrote: erratic php behavior PHP itself is generally not erratic and pretty straight forward in the way it parses code. You code either works or PHP tells you that it doesn't. You can however, increase decrease what error messages you receieve. Add one of the following Code to each Page you test / include in a config file. To display all errors except for notices: <?php ini_set('display_errors', 1); error_reporting(E_ALL ^ E_NOTICE); ?> To display all errors including notices: <?php ini_set('display_errors', 1); error_reporting(E_ALL); ?> (I think that's the right way round)
-
Jeffrey Webster wrote: erratic php behavior PHP itself is generally not erratic and pretty straight forward in the way it parses code. You code either works or PHP tells you that it doesn't. You can however, increase decrease what error messages you receieve. Add one of the following Code to each Page you test / include in a config file. To display all errors except for notices: <?php ini_set('display_errors', 1); error_reporting(E_ALL ^ E_NOTICE); ?> To display all errors including notices: <?php ini_set('display_errors', 1); error_reporting(E_ALL); ?> (I think that's the right way round)
Hi, Thanks for your reply and the code. I'm sorry but I didn't quite understand this: "Add one of the following Code to each Page you test / include in a config file." Should I create a php file (say, error_display.php) with the cited code and then include it at the top of each php page? Or should I be editing the php config file directly? Thanks for any clarification:). Jeff
-
Hi, Thanks for your reply and the code. I'm sorry but I didn't quite understand this: "Add one of the following Code to each Page you test / include in a config file." Should I create a php file (say, error_display.php) with the cited code and then include it at the top of each php page? Or should I be editing the php config file directly? Thanks for any clarification:). Jeff
Jeffrey Webster wrote:
Or should I be editing the php config file directly?
Edit the 'error_reporting' line (or add it) to your php.ini file to look like the following:
error_reporting = E_ALL
Then restart your web server. I would suggest creating your own custom error handler. The following example simply logs the error into a file storing what file the error occurred, what line it happened, the message given and dumps the variables currently stored in the symbol table.
<?php
// This function will be called for every error that occurs
function errorHandler($type, $message, $file, $line, $symboltable)
{// Log all errors in a file (New line at the end is deliberate) error\_log('ERROR in ' . $file . ' on line ' . $line . ' - ' . $message . ' \[var dump\] ' . print\_r($symboltable, true) . '
', 3, 'errors.log');
// If fatal error, die() as there is no use to carry on. if ($type == E\_USER\_ERROR) { die( $message ); } // Alert the user that an error has occurred. echo 'An error has occurred, sorry for the inconvenience.'; // Return true so that it doesn't execute the internal PHP error handler. return true;
}
// Report all errors. Unnecessary if it is enabled in the php.ini.
error_reporting(E_ALL);// Define custom handler.
set_error_handler('errorHandler');?>
More options of what you can do the
error_log()
function can do, such as email, write to the system logger etc., can be found in the documentation[^].If at first you don't succeed, you're not Chuck Norris.
-
Hi, Thanks for your reply and the code. I'm sorry but I didn't quite understand this: "Add one of the following Code to each Page you test / include in a config file." Should I create a php file (say, error_display.php) with the cited code and then include it at the top of each php page? Or should I be editing the php config file directly? Thanks for any clarification:). Jeff
Jeffrey Webster wrote: Should I create a php file (say, error_display.php) with the cited code and then include it at the top of each php page? Or should I be editing the php config file directly? Either. 1)Create a php file (say, error_display.php) with the cited code and then include it at the top of each php page. or 2) Use fly904's method. Custom error handler is better, but to start you should probably just get them showing up on the page you are working on.
-
Hi, I'm having major problems with erratic php behavior. I think it's something to do with the server, though I'm not sure. It is incomprehensible in a way that C++ or VB could never be: the same code will work and then not work even though no inputs or context have changed. I need to get a handle on this. A step in the right direction would be to get more information out of the server. Is there an "explicit" or "strict" option in php? I've searched for it here, and on the general Internet and haven't found it. I could try to explain the behavior but no one would believe me anyway. It is pretty much as if there were a "ghost in the machine" making arbitrary decisions as to when the code will work. Jeff
Check this out: http://www.faqts.com/knowledge_base/view.phtml/aid/651/fid/38[^]
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
The woods are lovely, dark and deep, But I have promises to keep, And miles to go before I sleep, And miles to go before I sleep!