cvs: phpdoc /en/reference/errorfunc/functions set-error-handler.xml trigger-error.xml

From: Date: Mon, 05 May 2003 17:38:24 +0000
Subject: cvs: phpdoc /en/reference/errorfunc/functions set-error-handler.xml trigger-error.xml
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969353194@lists.php.net to get a copy of this message
derick Mon May 5 13:38:24 2003 EDT Modified files: /phpdoc/en/reference/errorfunc/functions set-error-handler.xml trigger-error.xml Log: - Layout Index: phpdoc/en/reference/errorfunc/functions/set-error-handler.xml diff -u phpdoc/en/reference/errorfunc/functions/set-error-handler.xml:1.10 phpdoc/en/reference/errorfunc/functions/set-error-handler.xml:1.11 --- phpdoc/en/reference/errorfunc/functions/set-error-handler.xml:1.10 Sat Oct 26 16:40:42 2002 +++ phpdoc/en/reference/errorfunc/functions/set-error-handler.xml Mon May 5 13:38:24 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.10 $ --> +<!-- $Revision: 1.11 $ --> <!-- splitted from ./en/functions/errorfunc.xml, last change in rev 1.1 --> <refentry id="function.set-error-handler"> <refnamediv> @@ -60,44 +60,49 @@ <?php // redefine the user error constants - PHP 4 only -define ("FATAL",E_USER_ERROR); -define ("ERROR",E_USER_WARNING); -define ("WARNING",E_USER_NOTICE); +define ("FATAL", E_USER_ERROR); +define ("ERROR", E_USER_WARNING); +define ("WARNING", E_USER_NOTICE); // set the error reporting level for this script error_reporting (FATAL | ERROR | WARNING); // error handler function -function myErrorHandler ($errno, $errstr, $errfile, $errline) { +function myErrorHandler ($errno, $errstr, $errfile, $errline) +{ switch ($errno) { case FATAL: - echo "<b>FATAL</b> [$errno] $errstr<br>\n"; - echo " Fatal error in line ".$errline." of file ".$errfile; - echo ", PHP ".PHP_VERSION." (".PHP_OS.")<br>\n"; - echo "Aborting...<br>\n"; + echo "<b>FATAL</b> [$errno] $errstr<br />\n"; + echo " Fatal error in line $errline of file $errfile"; + echo ", PHP ".PHP_VERSION." (".PHP_OS.")<br />\n"; + echo "Aborting...<br />\n"; exit(1); break; case ERROR: - echo "<b>ERROR</b> [$errno] $errstr<br>\n"; + echo "<b>ERROR</b> [$errno] $errstr<br />\n"; break; case WARNING: - echo "<b>WARNING</b> [$errno] $errstr<br>\n"; + echo "<b>WARNING</b> [$errno] $errstr<br />\n"; break; - default: - echo "Unkown error type: [$errno] $errstr<br>\n"; + default: + echo "Unkown error type: [$errno] $errstr<br />\n"; break; } } // function to test the error handling -function scale_by_log ($vect, $scale) { - if ( !is_numeric($scale) || $scale <= 0 ) +function scale_by_log ($vect, $scale) +{ + if (!is_numeric($scale) || $scale <= 0) { trigger_error("log(x) for x <= 0 is undefined, you used: scale = $scale", FATAL); + } + if (!is_array($vect)) { trigger_error("Incorrect input vector, array of values expected", ERROR); return null; } + for ($i=0; $i<count($vect); $i++) { if (!is_numeric($vect[$i])) trigger_error("Value at position $i is not a number, using 0 (zero)", @@ -112,7 +117,7 @@ // trigger some errors, first define a mixed array with a non-numeric item echo "vector a\n"; -$a = array(2,3,"foo",5.5,43.3,21.11); +$a = array(2,3, "foo", 5.5, 43.3, 21.11); print_r($a); // now generate second array, generating a warning @@ -122,7 +127,7 @@ // this is trouble, we pass a string instead of an array echo "----\nvector c - an error\n"; -$c = scale_by_log("not array",2.3); +$c = scale_by_log("not array", 2.3); var_dump($c); // this is a critical error, log of zero or negative number is undefined @@ -149,7 +154,7 @@ ) ---- vector b - a warning (b = log(PI) * a) -<b>WARNING</b> [1024] Value at position 2 is not a number, using 0 (zero)<br> +<b>WARNING</b> [1024] Value at position 2 is not a number, using 0 (zero)<br /> Array ( [0] => 2.2894597716988 @@ -161,13 +166,13 @@ ) ---- vector c - an error -<b>ERROR</b> [512] Incorrect input vector, array of values expected<br> +<b>ERROR</b> [512] Incorrect input vector, array of values expected<br /> NULL ---- vector d - fatal error -<b>FATAL</b> [256] log(x) for x <= 0 is undefined, you used: scale = -2.5<br> - Fatal error in line 36 of file trigger_error.php, PHP 4.0.2 (Linux)<br> -Aborting...<br> +<b>FATAL</b> [256] log(x) for x <= 0 is undefined, you used: scale = -2.5<br /> + Fatal error in line 36 of file trigger_error.php, PHP 4.0.2 (Linux)<br /> +Aborting...<br /> ]]> </programlisting> </informalexample> Index: phpdoc/en/reference/errorfunc/functions/trigger-error.xml diff -u phpdoc/en/reference/errorfunc/functions/trigger-error.xml:1.3 phpdoc/en/reference/errorfunc/functions/trigger-error.xml:1.4 --- phpdoc/en/reference/errorfunc/functions/trigger-error.xml:1.3 Mon Jan 20 15:46:25 2003 +++ phpdoc/en/reference/errorfunc/functions/trigger-error.xml Mon May 5 13:38:24 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.3 $ --> +<!-- $Revision: 1.4 $ --> <!-- splitted from ./en/functions/errorfunc.xml, last change in rev 1.1 --> <refentry id="function.trigger-error"> <refnamediv> @@ -23,14 +23,15 @@ family of constants, and will default to <constant>E_USER_NOTICE</constant>. </para> <para> - This function is useful when + This function is useful when you need to generate a particular response to an exception at runtime. For example: <informalexample> <programlisting> <![CDATA[ -if (assert ($divisor == 0)) - trigger_error ("Cannot divide by zero", E_USER_ERROR); +if (assert ($divisor == 0)) { + trigger_error ("Cannot divide by zero", E_USER_ERROR); +} ]]> </programlisting> </informalexample>

« previous php.doc (#969353194) next »