Displaying syntax 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Displaying syntax errors

Post by twigletmac »

Since I can normally just edit the php.ini this hasn't come up for me before but, what can you do to make PHP show syntax errors if you can't?

Using ini_set('display_errors', true) only works if there aren't any major syntax errors according to the testing I've done. So, what workarounds are there?

Ta muchly,
Mac
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Might need this too:

Code: Select all

error_reporting(E_ALL);
Or maybe E_STRICT for PHP5.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

If you are refering to parse errors, there is nowt you can do without access to php.ini.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

/me wonders if a backtrace can be echoed purposefully even if error_dispay is disabled? Maybe from within an error handler you cooked up? Before the script terminates?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

If there are parse errors, you won't even be able to get that far :)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

It sounds to me like you just want to see if a page has correct syntax. Why not just run the file?

However, that seems like much too simplistic a solution, so I must be missing something. You can call a shell command to give you errors:

Code: Select all

echo shell_exec('php -l /path/to/somefile.php');
That should give you any parse errors.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply