Jump to content

no error is shown ( version 2)


hisoka
 Share

Recommended Posts

<?php
error_reporting( E_ALL );
ini_set( "display_errors", 1 );

echo "This string never ends;

 

although I use both of them in bold , no error was shown .

 

look "This string never ends; // without double quotes at the end and there is no ?> too and even so both error_reporting( E_ALL );
ini_set( "display_errors", 1 );

 

did not show any error

 

?????

Link to comment
Share on other sites

Your file has a syntax error. Syntax errors mean that the code does not get executed at all because PHP cannot figure out the structure of the code. Since the code never gets executed at all then the lines in bold do not get executed either. You should make sure that you have php.ini configured to log errors so that you can check that error log for syntax errors.

Link to comment
Share on other sites

IF the code is all php with no escaping to include text such as html a closing ?> is not required, so

<?php
error_reporting( E_ALL );
ini_set( "display_errors", 1 );
echo "This string never ends";

is valid, and will not throw an error.

Edited by dsonesuk
  • Like 1
Link to comment
Share on other sites

Understand the difference between parse errors (or compile-time errors) and run-time errors. PHP finds a parse error when it makes its first pass through the code to determine the structure so that it can execute the code during the second pass. If it cannot determine the structure of the code before executing then that is a parse error. Maybe the code has missing brackets, parentheses, etc and PHP cannot figure out what it is supposed to do. A run-time error happens while the code is executing, like you try to call a function that does not exist. Using functions like error_reporting or ini_set only affect run-time errors because those functions have to be executed to take effect. They don't even get executed if there is a parse error and PHP quits before executing the code.

 

The settings inside php.ini apply to all errors, because PHP loads those configuration options even before trying to parse the code. That's where your error reporting settings for the entire server should be. You should only use error_reporting or ini_set if you need to change things for a particular script. Otherwise set the appropriate settings for the entire server in php.ini.

 

One trick is to have a file which parses correctly, sets the appropriate options, and then includes another file. PHP will not try to parse the included file until it is included, and by that time the other lines will have executed to set the options.

 

<?php
error_reporting( E_ALL );
ini_set( "display_errors", 1 );
include 'file.php';
Otherwise, just set the options in php.ini.
Link to comment
Share on other sites

I understood very well what you talking about . However I would like to know how to see the errors someone made during parsing time ? If I am right , according to what you wrote to me , the error log is able to detect those errors that happen during parsing time so that when I open the error log file I see them but when I put this little code

 

<?

 

echo "good";

 

>

 

and run that , then opened my error log file , I did not notice any error although all these options are on :

 

display_errors = On //uncommented

log_errors = On //uncommented

display_startup_errors = On //uncommented

error_reporting = E_ALL //uncommented

 

 

 

This is what I meant by how to be able to see those errors ?

Edited by hisoka
Link to comment
Share on other sites

"Depending on which php.ini file you are editing, Apache php.ini file OR the actual PHP php.ini file"

 

Is there two php.ini files one for Apache and the other for php ?!!! to my information , there is only one php.ini file located inside the PHP folder . Besides , when I installed Apache 2.2.15 version and looked in all its folder , I did not see any php.ini file. As I said there is only a php.ini file and that is in PHP folder

Link to comment
Share on other sites

Any php.ini files in your localhost or localhost website folders then? since I don't know how far you have searched, or how your local server is setup I have to ask, as these are possible reasons it will fail, in mine there is a php.ini file in Apache sub folder /bin.

Link to comment
Share on other sites

The phpinfo page will show you which php.ini file is being used. Search that page for "php.ini", and also verify that phpinfo shows that the options are set to what you think they are. Also, if you haven't specified an error log then on Windows it will log errors to the Windows event log.

Link to comment
Share on other sites

Error messages say what PHP sees as incorrect, PHP does not have the psychic ability to enter your mind and figure out what you meant to do, and then tell you what you did wrong. PHP has no intelligence. You're the one with intelligence, it's up to you to figure out what you meant to do and what you did wrong.

Link to comment
Share on other sites

PHP errors are pretty clear for the most part and will include line numbers. What errors are you getting and which part don't you understand about them? You can search more information on all them, they will be documented on the PHP site.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...