PHP 4

[ PHP ]

(!!! Teleportom!!!)
: fopen, msql_num_fields, socket_write ...


15.

:

15-1. PHP
1E_ERROR  
2E_WARNING ( ) 
4 E_PARSE  
8 E_NOTICE ( , )  
16E_CORE_ERROR PHP PHP 4
32E_CORE_WARNING ( ) PHP 4
64E_COMPILE_ERROR PHP 4
128E_COMPILE_WARNING ( ) PHP 4
256E_USER_ERROR PHP 4
512E_USER_WARNING PHP 4
1024E_USER_NOTICE PHP 4
 E_ALL ,  

( ) , . . ,   '|', '~', '!' '&' php.ini php3.ini.

PHP 4 error_reporting E_ALL & ~E_NOTICE, , E_NOTICE-level. PHP 3 (E_ERROR | E_WARNING | E_PARSE) . , , , PHP 3 php3.ini, error_reporting ; 7 .

ini- error_reporting, Apache httpd.conf- php_error_reporting (php3_error_reporting PHP 3) , , error_reporting().

!

PHP 3 PHP 4 error_reporting(), , E_COMPILE_ERROR. - .

"@", . track_errors , $php_errormsg.

: @ error-control- , .

!

@ error-control- , . , , , @ , .

. , - ( XML-) e-mail .
15-1.
<?php
//     
error_reporting(0);

//    
function userErrorHandler ($errno, $errmsg, $filename, $linenum, $vars) {

    //     
    $dt = date("Y-m-d H:i:s (T)");

    //     ;
    //      
    // 2,8,256,512  1024
    $errortype = array (
                1   =>  "Error",
                2   =>  "Warning!",
                4   =>  "Parsing Error",
                8   =>  "Notice",
                16  =>  "Core Error",
                32  =>  "Core Warning!",
                64  =>  "Compile Error",
                128 =>  "Compile Warning!",
                256 =>  "User Error",
                512 =>  "User Warning!",
                1024=>  "User Notice"
                );
    //  ,   vartrace  
    $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);
    
    $err = "<errorentry>\n";
    $err .= "\t<datetime>".$dt."</datetime>\n";
    $err .= "\t<errornum>".$errno."</errornum>\n";
    $err .= "\t<errortype>".$errortype[$errno]."</errortype>\n";
    $err .= "\t<errormsg>".$errmsg."</errormsg>\n";
    $err .= "\t<scriptname>".$filename."</scriptname>\n";
    $err .= "\t<scriptlinenum>".$linenum."</scriptlinenum>\n";

    if (in_array($errno, $user_errors))
        $err .= "\t<vartrace>".wddx_serialize_value($vars,"Variables")."</vartrace>\n";
    $err .= "</errorentry>\n\n";
    
    //  
    // echo $err;

    //   error log  e-mail,     
    error_log($err, 3, "/usr/local/php4/error.log");
    if ($errno == E_USER_ERROR)
        mail("[email protected]","Critical User Error",$err);
}


function distance ($vect1, $vect2) {
    if (!is_array($vect1) || !is_array($vect2)) {
        trigger_error("Incorrect parameters, arrays expected", E_USER_ERROR);
        return NULL;
    }

    if (count($vect1) != count($vect2)) {
        trigger_error("Vectors need to be of the same size", E_USER_ERROR);
        return NULL;
    }

    for ($i=0; $i<count($vect1); $i++) {
        $c1 = $vect1[$i]; $c2 = $vect2[$i];
        $d = 0.0;
        if (!is_numeric($c1)) {
            trigger_error("Coordinate $i in vector 1 is not a number, using zero", 
                            E_USER_WARNING);
            $c1 = 0.0;
        }
        if (!is_numeric($c2)) {
            trigger_error("Coordinate $i in vector 2 is not a number, using zero", 
                            E_USER_WARNING);
            $c2 = 0.0;
        }
        $d += $c2*$c2 - $c1*$c1;
    }
    return sqrt($d);
}

$old_error_handler = set_error_handler("userErrorHandler");

//  ,  
$t = I_AM_NOT_DEFINED;

//   ""
$a = array(2,3,"foo");
$b = array(5.5, 4.3, -1.6);
$c = array (1,-3);

//   
$t1 = distance($c,$b)."\n";

//     
$t2 = distance($b,"i am not an array")."\n";

//  
$t3 = distance($a,$b)."\n";

?>

, , .

. error_reporting(), error_log(), set_error_handler(), restore_error_handler(), trigger_error(), user_error()




: 3119 .

: - |  -