set_error_handler
��������� ����������������� ����������� ������.
��������� :
string set_error_handler(string error_handler)
������� ���������� ��� �������, ����� ������������ � �������� ����������� ������ (��� FALSE ��� ������), � �������������, � �������� ������ �����������, ������� � ��������� � ��������� error_handler ������.
������ ���������������� ���������� ������ �������� � ���� � �������� trigger_error(), ������������ ������. ��� ����� ���� ������������ (������� ����������� ����������� ������ � ������������ � C) ��� ������������ ���������� �������� (��������, �������� ��������� ������), ���� �������� �� ����� ��������� �����������.
�������, ��������������� � �������� ����������� ������, ������ ��������� ���� ���������� (��� ��������� �������� ��������������� � ����� �� ��������������):
��� ������
������, ����������� ������
��� ��������, � ������� ��������� ������
����� ������ ��������, ���������� ������
�������� (������, ���������� �������� ����������, � ������ ������������� ������)
����� �������, ��� ��������� �������� � ����������� ���������� ���� (��������, � ������� ������� die()), ����, �������, � ���� ���� �������������. ���� ���������� ������ ����������� � ������� return, �� ���������� �������� ������������ � ���� �����, � ������� �������� ������ (�� ���� ����������� ����������, ������� ������� �� ��� �����������, � ������� �������� ������).
��������� ����������������� ����������� ������.
��������� :
string set_error_handler(string error_handler)
������� ���������� ��� �������, ����� ������������ � �������� ����������� ������ (��� FALSE ��� ������), � �������������, � �������� ������ �����������, ������� � ��������� � ��������� error_handler ������.
������ ���������������� ���������� ������ �������� � ���� � �������� trigger_error(), ������������ ������. ��� ����� ���� ������������ (������� ����������� ����������� ������ � ������������ � C) ��� ������������ ���������� �������� (��������, �������� ��������� ������), ���� �������� �� ����� ��������� �����������.
�������, ��������������� � �������� ����������� ������, ������ ��������� ���� ���������� (��� ��������� �������� ��������������� � ����� �� ��������������):
<? // ���������� ��������� ���������������� ������ define(FATAL, E_USER_ERROR); define(ERROR, E_USER_WARNING); define(WARNING, E_USER_NOTICE); // ����������, ����� ������ ������ �������������� � �������� error_reporting (FATAL | ERROR | WARNING); // ���������������� ���������� ������ function myErrorHandler($errno,$errstr,$errfile,$errline) { switch ($errno) { case FATAL: echo "<b>����������� ������</b> [$errno] $errstr<br>\n"; echo "� ������: $errline �����:".$errfile; echo ", PHP ".PHP_VERSION." (".PHP_OS.")<br>\n"; echo "Aborting...<br>\n"; exit -1; break; case ERROR: echo "<b>������</b> [$errno] $errstr<br>\n"; break; case WARNING: echo "<b>��������������</b> [$errno] $errstr<br>\n"; break; default: echo "����������� ��� ������: [$errno] $errstr<br>\n"; } } // ������� ��� �������� ��������� ������ // (��������������� ������� function scale_by_log($vect, $scale) { if(!is_numeric($scale) || $scale <= 0) trigger_error("��������� log(x) ��� x <= 0 ������. ", "(x = $scale)", FATAL); if(!is_array($vect)) { trigger_error("��������� ������ ", ERROR); return null; } for($i=0; $i<count($vect); $i++) { if(!is_numeric($vect[$i])) trigger_error("������� ($i) �� ����� � ��� ��������� ��������� 0", WARNING); $temp[$i]=log($scale)*$vect[$i]; } return $temp; } // ���������� ���������������� ���������� ������ $old_error_handler=set_error_handler("myErrorHandler"); $a=array(2,3,"foo",5.5,43.3,21.11); print_r($a); $b=scale_by_log($a,M_PI); // ����� �������� �������������� echo "������, ���������������� �� ��������(��): "; print_r($b); $c=scale_by_log("not array",2,3); // ����� ������ var_dump($c); $d=scale_by_log($a, -2.5); // ����� ����������� ������ echo "����������� ��������..."; ?>��� ���������� �������� ����� ����� ���������:
Array ( [0] => 2 [1] => 3 [2] => foo [3] => 5.5 [4] => 43.3 [5] => 21.11 ) <b>��������������</b> [1024] ������� (2) �� �����, � ��� ��������� ��������� 0<br> ������, ���������������� �� ��������(��): Array ( [0] => 2.2894597716988 [1] => 3.4341896575482 [2] => 0 [3] => 6.2960143721717 [4] => 49.566804057279 [5] => 24.165247890281 ) <b>������</b> [512] ��������� ������ <br> NULL <b>����������� ������</b> [256] ��������� log(x) ��� x <=0 ������, (x = -2.5)<br> � ������: 37, ����� E:\www\exampl.php, PHP 4.0.5 (WINNT)<br> Aborting...<br>�� ���������, ��� ��� ��������� ����������������� ����������� ������ ����������� ���������� PHP �� ������������. ��������� error_reporting() ����� �� ����� ����� �������, � ���������������� ���������� ������ ����� ������������ ��� ���� ������ (�������� error_reporting() ����� �������� � ����������� �������������). ��������, ��� ��� ������ ����� ����� 0, ���� ������ �������� � �������, ����� ������ ��� ������� ��� ���������� ���������� "@".
����� �������, ��� ��������� �������� � ����������� ���������� ���� (��������, � ������� ������� die()), ����, �������, � ���� ���� �������������. ���� ���������� ������ ����������� � ������� return, �� ���������� �������� ������������ � ���� �����, � ������� �������� ������ (�� ���� ����������� ����������, ������� ������� �� ��� �����������, � ������� �������� ������).