Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6
This is the forum to discuss the Wrox book Beginning PHP, Apache, MySQLWeb Development by Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner; ISBN: 9780764557446
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 6th, 2004, 02:25 AM
Registered User
 
Join Date: Apr 2004
Location: , , United Kingdom.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Parse error in error handler (Chapter 8)

Hi. I'm working on Chapter 8, pages 230-231. I've used the code to create a page called error_reporting and including it in each to trap errors. When I ran a page with the include file I got the error:

Parse error: parse error, unexpected '[', expecting ',' or ';' in /(path to file)/error_reporting.php on line 5

My code is here:

<?php
//create your error handler function
function handler($error_type, $error_message, $error_file, $error_line)
{
     global $_SERVER['HTTP_HOST'], $_SERVER['HTTP_USER_AGENT'], $_SERVER['REMOTE_ADDR'], $_SERVER['REQUEST_URI'];

     switch($error_type)
     {
          //fatal error
          case E_ERROR:
               $to = "Administrator <webmaster@daycentreconnections.org";

               $subject = "Custom Error Handling";

               $body = "<html>";
               $body .= "<head>";
               $body .= "<title></title>";
               $body .= "</head>";
               $body .= "<body>";
               $body .= "<h1>Fatal Error</h1>";
               $body .= "Error received was a <b>" . $error_type . "</b> error.<br>";
               $body .= "The page that generated the error was: <b>" . $error_file . "</b>";
               $body .= " and was generated on line: <b>" . $error_line . "</b><br>";
               $body .= "The generated error message was:" . $error_message;
               $body .= "</body>";
               $body .= "</html>";

               $headers = "MIME-Version: 1.0\r\n";
               $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

               $headers .= "From: Apache Error <host@yourdomain.com>\r\n";
               $headers .= "Cc: webmaster@daycentreconnections.org\r\n";

               mail($to, $subject, $message, $headers);
               die(); //kill the script
               break;
          //warnings
          case E_WARNING:

               $to = "Administrator <webmaster@daycentreconnections.org>";

               $subject = "Custom Error Handling";

               $body = "<html>";
               $body .= "<head>";
               $body .= "<title></title>";
               $body .= "</head>";
               $body .= "<body>";
               $body .= "<h1>Warning</h1>";
               $body .= "Error received was a <b>" . $error_type . "</b>
                     error.<br>";
               $body .= "The page that generated the error was: <b>" .
                    $error_file . "</b>";
               $body .= " and was generated on line: <b>" . $error_line .
                    "</b><br>";
               $body .= "The generated error message was:" . $error_message;
               $body .= "</body>";
               $body .= "</html>";

               $headers = "MIME-Version: 1.0\r\n";
               $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

               $headers .= "From: Apache Error <webmaster@daycentreconnections.org>\r\n";
               $headers .= "Cc: webmaster@daycentreconnections.org\r\n";

               mail($to, $subject, $message, $headers);
               break;
               //script will continue

          //notices
          case E_NOTICE:
               //don't show notice errors
               break;
     }
}
/*
set error handling to 0
we will handle all error reporting
only notifying admin on warnings and fatal errors
don't bother with notices as they are trivial errors
really only meant for debugging
*/
error_reporting(0);

//set the error handler to be used
set_error_handler("handler");

/*
Create the rest of your page here.
We will not be displaying any errors
We will be e-mailing the admin an error message
Keep in mind that fatal errors will still halt the
execution, but they will still notify the admin
*/
?>

I can't see what the problem is, especially as I have cut and paste the code from the code download that goes with the book. Surely the [ is needed in the code?

If there's an error in the code I'll let the authors know so that it can be added to the book's Errata.


Reply With Quote
  #2 (permalink)  
Old August 6th, 2004, 08:59 AM
Authorized User
 
Join Date: Jun 2004
Location: , , .
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There's no need to declare anything in the $_SERVER array as global. By default it's global. Same goes for $_GET, $_POST, etc...
Looks like an error in the code in the book.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch 4: Parse error: syntax error, unexpected T_SL hanizar77 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 June 23rd, 2008 09:17 PM
PHP Parse error: parse error, unexpected T_STRING geminient PHP How-To 4 August 18th, 2007 02:27 AM
Parse error: parse error, unexpected $end Ayodeji Adegbaju Pro PHP 3 January 12th, 2007 12:21 PM
Chapter 2 {curly bracket} parse error of DEATH psychot BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 3 August 5th, 2005 03:36 PM
Chapter 5 Parse Error razorack BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 February 6th, 2005 10:43 AM



All times are GMT -4. The time now is 09:16 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.