Mantis Bugtracker
  

Viewing Issue Advanced Details Jump to Notes ] View Simple ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0000672 [Quercus] minor always 01-04-06 08:18 01-09-06 19:00
Reporter creich View Status public  
Assigned To ferg
Priority normal Resolution fixed Platform
Status closed   OS
Projection none   OS Version
ETA none Fixed in Version 3.0.18 Product Version
  Product Build
Summary 0000672: trigger_error or set_error_handler not working
Description I haven't debugged this yet...

The following script is from http://us3.php.net/set_error_handler [^]

<?php
// set the error reporting level for this script
error_reporting(E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE);

// error handler function
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
  switch ($errno) {
  case E_USER_ERROR:
   echo "My ERROR [$errno] $errstr
\n";
   echo " Fatal error in line $errline of file $errfile";
   echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")
\n";
   echo "Aborting...
\n";
   exit(1);
   break;
  case E_USER_WARNING:
   echo "My WARNING [$errno] $errstr
\n";
   break;
  case E_USER_NOTICE:
   echo "My NOTICE [$errno] $errstr
\n";
   break;
  default:
   echo "Unkown error type: [$errno] $errstr
\n";
   break;
  }
}

// function to test the error handling
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", E_USER_ERROR);
  }

  if (!is_array($vect)) {
   trigger_error("Incorrect input vector, array of values expected", E_USER_WARNING);
   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)", E_USER_NOTICE);
     $temp[$i] = log($scale) * $vect[$i];
   }
   return $temp;
  }

// set to the user defined error handler
$old_error_handler = set_error_handler("myErrorHandler");

// 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);
print_r($a);

// now generate second array, generating a warning
echo "----\nvector b - a warning (b = log(PI) * a)\n";
$b = scale_by_log($a, M_PI);
print_r($b);

// 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);
var_dump($c);

// this is a critical error, log of zero or negative number is undefined
echo "----\nvector d - fatal error\n";
$d = scale_by_log($a, -2.5);

?>

It is supposed to output something like:

vector a
Array
(
    [0] => 2
    [1] => 3
    [2] => foo
    [3] => 5.5
    [4] => 43.3
    [5] => 21.11
)
----
vector b - a warning (b = log(PI) * a)
WARNING [1024] Value at position 2 is not a number, using 0 (zero)

Array
(
    [0] => 2.2894597716988
    [1] => 3.4341896575482
    [2] => 0
    [3] => 6.2960143721717
    [4] => 49.566804057279
    [5] => 24.165247890281
)
----
vector c - an error
ERROR [512] Incorrect input vector, array of values expected

NULL
----
vector d - fatal error
FATAL [256] log(x) for x <= 0 is undefined, you used: scale = -2.5

Fatal error in line 36 of file trigger_error.php, PHP 4.0.2 (Linux)

Aborting...



INSTEAD IT outputs only:

vector a
Array
(
    [0] => 2
    [1] => 3
    [2] => foo
    [3] => 5.5
    [4] => 43.3
    [5] => 21.11
)
----
vector b - a warning (b = log(PI) * a)
/C:/Resin/resin/webapps/ROOT/triggererror.php:38: Fatal Error: log(x) for x <= 0 is undefined, you used: scale = M_PI


In other words... vector b was only supposed to issue a warning.
Steps To Reproduce
Additional Information
Attached Files

- Relationships

- Notes
(0000653)
ferg
01-09-06 19:00

php/180d
 

- Issue History
Date Modified Username Field Change
01-04-06 08:18 creich New Issue
01-09-06 19:00 ferg Note Added: 0000653
01-09-06 19:00 ferg Assigned To  => ferg
01-09-06 19:00 ferg Status new => closed
01-09-06 19:00 ferg Resolution open => fixed
01-09-06 19:00 ferg Fixed in Version  => 3.0.18
01-09-06 19:00 ferg View Status @0@ => public


Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
29 total queries executed.
26 unique queries executed.
Powered by Mantis Bugtracker