Jump to content

Error_reporting And Array Printing


Alexancho
 Share

Recommended Posts

I started to learn PHP and am facing to problems now.1. I use

<?php error_reporting(E_ALL);?>

and don't get any report.2. Cod like this

<?php$firstquarter = array(1 => 'January', 'February', 'March');print_r($firstquarter);?>

prints all the data in a one line:

Array ( [1] => January [2] => February [3] => March )
when it must be something like this:
Array( [1] => January [2] => February [3] => March)
Link to comment
Share on other sites

1. Well, do you actually have any errors?2. That's because in HTML newlines aren't rendered - you have to use break tags (e.g. through nl2br()) (or you can enclose the text in a tag like <pre>). You can also change the page's content-type to something like text/plain.

Link to comment
Share on other sites

Remember that if you turn on error reporting in the script you are testing, it will only report runtime errors. Syntax errors (parse errors) will be caught before the script is actually executed, so the statements that turn on error reporting will also not execute. This is what leads to the dreaded "blank screen." Errors like that can be reported only if error reporting is turned on in your settings, or if you include your script in a kind of shell script that has error reporting turned on. I use a thing like this sometimes:test.php

<?php   error_reporting(E_ALL);   ini_set('display_errors', 1);   if (!empty($_GET['file'])){	  include $_GET['file'];   }?>

Which I call from my address bar like this:www.me.com/test.php?file=newscript.phpWhere newscript.php is the script I'm evaluating. Included files are parsed at runtime, so this means test.php will execute for certain. Since test.php turns on the error reporting, and is guaranteed to execute, syntax errors in newscript.php will always be reported.

Edited by Deirdre's Dad
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...