note 118928 added to class.divisionbyzeroerror

From: Date: Tue, 01 Mar 2016 05:27:43 +0000
Subject: note 118928 added to class.divisionbyzeroerror
Groups: php.notes 
Request: Send a blank email to php-notes+get-205071@lists.php.net to get a copy of this message
Note that on division by zero 1/0 and module by zero 1%0 an E_WARNING is triggered first (probably for backward compatibility with PHP5), then the DivisionByZeroError exception is thrown next. The result is, for example, that if you set the maximum level of error detection with error_level(-1) and you also map errors to exception, say ErrorException, then on division by zero only this latter exception is thrown reporting "Division by zero". The result is that a code like this: <?php // Set a safe environment: error_reporting(-1); // Maps errors to ErrorException. function my_error_handler($errno, $message) { throw new ErrorException($message); } try { echo 1/0; } catch(ErrorException $e){ echo "got $e"; } ?> allows to detect such error in the same way under PHP5 and PHP7, although the DivisionByZeroError exception is masked off by ErrorException. ---- Server IP: 72.52.91.14 Probable Submitter: 88.149.172.234 ---- Manual Page -- http://php.net/manual/en/class.divisionbyzeroerror.php Edit -- https://master.php.net/note/edit/118928 Del: integrated -- https://master.php.net/note/delete/118928/integrated Del: useless -- https://master.php.net/note/delete/118928/useless Del: bad code -- https://master.php.net/note/delete/118928/bad+code Del: spam -- https://master.php.net/note/delete/118928/spam Del: non-english -- https://master.php.net/note/delete/118928/non-english Del: in docs -- https://master.php.net/note/delete/118928/in+docs Del: other reasons-- https://master.php.net/note/delete/118928 Reject -- https://master.php.net/note/reject/118928 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#205071) next »