views:

127

answers:

3

I'm new to PHP, started with Code Igniter and MAMP. I start the server from the MAMP application, and write PHP in the text editor.

When errors occur in the code, the page doesn't display anything! Is there anyway to see the errors on console? or PHP just doesn't show errors?

I'm used to Eclipses console when developing Java, is there anything similar?

+2  A: 

Error Reporting


In your code add :

 error_reporting(E_ALL);
 // I don't know if you need to wrap the 1 inside of double quotes.
 ini_set("display_startup_errors",1);
 ini_set("display_errors",1);

or you can do it from your php.ini file.

http://php.net/manual/en/errorfunc.configuration.php


I'm used to Eclipses console when developing Java, is there anything similar?

Yes, there is Zend Studio - Eclipse, and also PHP IDE by Eclipse.

ZS - http://www.zend.com/en/products/studio/

Eclipse - http://www.eclipse.org/downloads/

Laykes
this doesn't solve my problem, sometimes i forget a brace or a semicolon, the page just don't show anything
medopal
That will show the error. It is possible that you haven't enabled it correctly. Do a phpinfo(); and then take a look at the output. I am sure you will see that you haven't actually enabled Error reporting. error_reporting( E_ALL) will only work if errors are enabled. It is probably my mistake for not saying so.
Laykes
Yes, of course this won't show parse errors, for obvious reasons.
Col. Shrapnel
Thanks, im trying Eclipse PHP and Zend now, i dont think CodeIgniter is the perfect answer for beginners.
medopal
A: 

There are many fancy ways, similar to your eclipse console, but only 2 that works everythere.

First of all you have to decide, where you want to see your errors - online or in the log file. Usually we set online for developers machine and log for the public server. Unix-way for log is often used - tail -f /path/error_log

To set bullet-proof settings use either php config or apache config. So, to display errors online,
set display_errors = on in the php.ini file (be sure you edit working one)
or set php_value display_errors = 1 in the httpd.conf/.htaccess

For the public server on the shared hosting I usually add these lines into .htaccess:

php_value display_errors = 0
php_value log_errors = 1
php_value error_log = "/path/to/log.file" #if I want to have it separate from webserver's error log

Reporting level always remain the same and set in the config php file with

 error_reporting(E_ALL);   
Col. Shrapnel
+1  A: 

The errors should be displayed, looks like a supression issue which the others have covered. Something to look into is the application/config/config.php file that contains run-time configuration for the CodeIgniter framework:

(starting line number 166:)

166 |    0 = Disables logging, Error logging TURNED OFF
167 |    1 = Error Messages (including PHP errors)
168 |    2 = Debug Messages
169 |    3 = Informational Messages
170 |    4 = All Messages
171 |
172 | For a live site you'll usually only enable Errors (1) to be logged otherwise
173 | your log files will fill up very fast.
174 |
175 */
176 $config['log_threshold'] = 4;

This throws all errors, even if they aren't displayed into the Codeigniter logs folder (refer to your documentation for the location of this in your installed version.)

Hope that helped!

seacode