Parse errors are not displayed
I want PHP to display parse errors on screen. What I get instead is a blank page. Nothing gets written to server’s error log file. My setup: PHP5.2.9/IIS 6 (not Apache!). My PHP.INI:
error_reporting=E_STRICT display_errors = On display_startup_errors = On log_errors = On error_log = "C:\Program Files\Zend\ZendServer\logs\php_error.log"
How do I get parse or fatal errors to be either logged or shown on screen? Thanks, Temuri UPDATE: After playing with different switches it looks to be an IIS specific problem. ANY IDEAS FOLKS?
Is PHP installed as cgi or isapi module? Did you check the effective setting of display_startup. with var_dump(ini_get(‘display_startup_errors’), get_cfg_var(‘display_startup_errors’)); ?
Have you tried to execute the script on the commandline? «php -f scriptname.php», or try to check the syntax with the «-l» flag.
8 Answers 8
Setting error level in php file itself does not resolve the problem here because the file itself cannot be parsed !!
You need to change error_reporting line in your php.ini as follows:
BTW: There are some examples in php.ini file about what to do to display which type of error messages.
Apache doesn’t always like to report parsing errors either. From the command line, run
The -l switch tells PHP to check file syntax. See the man page.
That’s some help, but all it tells you is that you do have parsing errors, but it give no indication as to where those errors might be!
To the most recent of my knowledge, the lint switch will report the nature and location of the first syntax error it finds within the given file.
E_STRICT is not included in E_ALL (until PHP 6). If you want to keep getting E_STRICT
error_reporting = E_ALL | E_STRICT
error_reporting( E_ALL | E_STRICT );
You’ll need to set the error reporting level (and display_errors) in php.ini to see syntax errors. If PHP encounters a syntax error, the runtime doesn’t get executed, so setting at runtime won’t work. (See the display_errors link.)
I really don’t recall if that was a valid argument to error_reporting() when I wrote this answer 6 years ago.
You can verify the script syntax with this command in terminal:
Personally, I added this line to my ~/.bash_profile file so I can easily run php -l on all files in the current working directory:
If you’re really hardcore, you can even run your app from the command line. You’ll have a much better chance of seeing compile-time errors, and it’s just kinda cool.
You can use the $argv variable to get the first argument, $argv[1], then use that as the request.
Then you can run your script via command line. This would be the equivalent of visiting: your-webapp.com/request/uri/here
php /path/to/script.php request/uri/here
Here is a more comprehensive example for running CodeIgniter via command line. It should work for many other frameworks too: http://phpstarter.net/2008/12/run-codeigniter-from-the-command-line-ssh/
As Rasmus Lerdorf suggests, always use error_reporting(-1) on development server.
I can see that this was your first answer to a question, so you didn’t have the rep to post this as a comment, but in the future, you might want to consider posting this as a comment. Answers are supposed to be a solution to the problem that you are pretty confident will solve the problem.
PHP Tip — error_reporting(-1) at the top of your script during dev to turn on all warnings, notices, etc in all versions of PHP twitter.com/rasmus/status/7448448829
Re: Blank screen of php death death, I discovered that setting
php_value error_reporting «E_ALL» or php_value error_reporting 8192
in .htaccess on my Windows 7, Wampserver w/ apache 2.2.4 and php 5.3.13 are sure ways to get the blank php error screen — today, June 3, 2014. These htaccess lines DO set the desires value in phpinfo(), but the display of the errors happens only when the line is commented out (not used) in htaccess.
BUT. the next minute I discover that
php_value error_reporting 8191
DOES set the phpinfo() value AND also allows display of the error messages to the browser! D’oh! It must be an integer and also apparently a particular or valid integer, and not just a large enough integer!
Error Parsing JSON file with PHP
now, I would like to get first_name . how can I get that ? I tested below code, but it doesn’t work :
$json_a = json_decode($content, true); $first_name = $json_a->message->from->first_name; //it returns nothing.
6 Answers 6
$json_a = json_decode($content, true); ^^^^
That true forces the output of json_decode to be an array, but you are trying to treat it like an object. Remove that argument or use array syntax:
$first_name = $json_a['message']['from']['first_name'];
use only json_decode($content) remove true
$json_a = json_decode($content); echo $json_a->message->from->first_name;
True convert the output of json_decode to be an array
$json_a = json_decode($content, true); $first_name = $json_a->message->from->first_name; //it returns nothing.
That’s because the function returns an associative array, and not an object.
By using -> you’re trying to access object properties of $json_a . What you’re really looking for is:
$json_a["message"]["from"]["first_name"]
This way you’re accessing the associative array values by their key, and not trying to access object properties.
I hope this helped,
Sebastian
$json_a = json_decode($content); $first_name = $json_a->message->from->first_name;
$json_a = json_decode($content,true); $first_name = $json_a[message][from][first_name];
You’re passing true as the second argument to json_decode which tells it to return an associative array rather than an object.
Either remove the second argument (or change it to the default, false ), or access the fields using array syntax:
$first_name = $json['message']['from']['first_name'];
json_decode() is a php function used to decode json into either php standard object or an associative array dependent upon argument passed to it
When true it will return an associative otherwise by default it returns standard PHP object
According to your requirement please try executing following code snippet for retrieving first name from json document.
$json_a = json_decode($content, true); $first_name = $json_a['message']['from']['first_name'];
For more detailed description regarding parsing json documents in php please refer the documentation in following URL
Parse error: Syntax error, unexpected end of file in my PHP code
A year and a half hence, it is funny that this question was closed because it is too localized but it has got almost 50k views.
I agree. this totally fixed my problem. Not localized at all in regards to the question and the solution.
19 Answers 19
You should avoid this (at the end of your code):
You shouldn’t put brackets directly close to the open/close php tag, but separate it with a space:
I had similar ptoblem but my case was that i had short_open_tag = Off in my php.ini. When i turned it to On, my code worked.
Note while Apache accepts this Nginx does not (or rather fcgi does not) so if your stumped by why this is working on one web server and not another you know why
I had the same error, but I had it fixed by modifying the php.ini file.
then open it with your favorite editor.
Look for a short_open_tag property, and apply the following change:
; short_open_tag = Off ; previous value short_open_tag = On ; new value
This answer is especially important when dealing with legacy code. I have inherited code written by someone else, and the codebase was full of of (note, the missing php ). I am tasked to add or change features, and it typically isn’t a good idea to just go around changing everything just for one or two features. Your answer really helped.?>
Spot on, this is especially noteworthy if you have upgraded to the newer Plesk hosting software for instance or upgraded your PHP version. We found the php.ini settings got trashed and we had to go through set them again, this particular one was required to avoid the unexpected end of file error
I had the same error, but I had it fixed by modifying the php.ini and / or editing the PHP file!
There are two different methods to get around the parse error syntax.
Method 1 (Your PHP file)
Avoid in your PHP file this:
Make sure you put it like this
Your code contains
NOTE: The missing php after
Method 2 (php.ini file)
There is also a simple way to solve your problem. Search for the short_open_tag property value (Use in your text editor with Ctrl + F !), and apply the following change:
NOTE: Reload your Server (like for example: Apache) and reload your PHP webpage in your browser.
Just go to php.ini then find short_open_tag= Off set to short_open_tag= On
Also, watch out for heredoc closing identifiers.
Invalid Example:
// it's not working. function findAll() < $query=
This will throw an exception that resembles the following:
Parse error: syntax error, unexpected end of file in [. ][. ] on line 5
where number 5 might be the last line number of your file.
According to php manual:
Warning It is very important to note that the line with the closing identifier must contain no other characters, except a semicolon (;). That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by the local operating system. This is \n on UNIX systems, including macOS. The closing delimiter must also be followed by a newline.
TLDR: Closing identifiers should NOT be indented.
Valid Example:
Parse error PHP file
I was moving my site and everything is working great except on one page I get the following error: Parse error: syntax error, unexpected $end, expecting T_VARIABLE or T_DOLLAR_OPEN_CURLY_BRACES or T_CURLY_OPEN in domain/details.php on line 85 It was giving other errors that I manged to fix but this one I can not. The following is lines 80-85 of the details.php page. Thats the end of the file. Any help would be great
=================== Add new: Thanks. I treid all the above ways and it still gives error. Now it says line 84(which is last line here). This is what I changed it to:
> function desktop() < if(DESKTOP === true) " rel="nofollow"> > function icon_facebook() < if(FACEBOOK === true) " rel="nofollow"> > function icon_linkedin() < if(LINKEDIN === true) " rel="nofollow"> > function slogan() < if(SLOGAN === true) "> > > $snippets = new Snippets; ?>