Help! Can't show errors

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
MAtkins
Forum Newbie
Posts: 17
Joined: Fri Apr 02, 2010 3:55 pm

Help! Can't show errors

Post by MAtkins »

Hi:

I'm an old VB, ASP, C# ASP.NET programmer who got fed up and decided to go w/ php.

I absolutely cannot get this thing to display syntax errors.
This is at the top of every page:
error_reporting(E_ALL);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');

Almost NEVER will it display an error.
I spend more time trying to find typos than anything else on this project.

Is there *any* way to display syntax errors or does php simply leave us in the dark?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help! Can't show errors

Post by requinix »

First, by the time your script begins running PHP has already "started up". Not only can you not change the display_startup_errors setting in your code, if you could it would be too late to make any difference.

You have that code in the file with problems, correct?
Before your code executes PHP has to parse the file. As ini_set doesn't get any special treatment, PHP won't know that you want parse errors displayed when it finds them. Similarly error_reporting (as far as parse errors are concerned) won't do anything.

To show parse errors, you need to change display_errors and error_reporting before the buggy script can be loaded. That means
- in the main php.ini file
- in some additional INI files (though there generally aren't any)
- in a per-user php.ini (PHP as CGI) or with php_value in a .htaccess (PHP as an Apache module)
- in one file that includes or requires the buggy file (because PHP won't load the buggy file until after some code has executed)
MAtkins
Forum Newbie
Posts: 17
Joined: Fri Apr 02, 2010 3:55 pm

Re: Help! Can't show errors

Post by MAtkins »

tasairis thanks.
Yes that makes all the sense in the World.
It's 'not' a compiled app.
I actually had php.ini open and almost did as you recommend.
For some reason I didn't think my way through that and left those vars off.

Thanks for the help:)
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Help! Can't show errors

Post by califdon »

Thanks, tasairis, for a clear explanation of the PHP parsing process. We should make that a 'sticky' in this forum.

To MAtkins: most of us do without such error reporting, but it's a traumatic shock when you first come to PHP. The issue is that you must avoid doing that on your production server, because it's going to affect every script that runs in that directory (or on the entire site), which would not be nice if it's your production system!
MAtkins
Forum Newbie
Posts: 17
Joined: Fri Apr 02, 2010 3:55 pm

Re: Help! Can't show errors

Post by MAtkins »

Well, I hoped . . .

I changed the vars in the php.ini file.
I know it's the right php.ini file because I changed the default temp folder and that worked.
I stopped & restarted the IIS hoping that might be the problem.

I'm still getting just a blank page with most errors.
Is there any way to get it to tell me what is wrong?
MAtkins
Forum Newbie
Posts: 17
Joined: Fri Apr 02, 2010 3:55 pm

Re: Help! Can't show errors

Post by MAtkins »

I found this.
I had to set:
error_reporting = E_ALL
in the php.ini file

Thanks for your help:)
Post Reply