#51010 [Opn]: Bad example
| From: | rquadling@php.net | Date: | Thu, 11 Feb 2010 11:06:21 +0000 |
| Subject: | #51010 [Opn]: Bad example | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-3867@lists.php.net to get a copy of this message | ||
ID: 51010
Updated by: rquadling@php.net
Reported By: chris dot dickinson at web dot de
Status: Open
Bug Type: Documentation problem
PHP Version: Irrelevant
New Comment:
assert() returns the state of the test.
If $divisor == 0, then assert() will return true and the trigger will
be
called.
For this sort of test, maybe a plain if($divisor == 0) is enough.
Previous Comments:
------------------------------------------------------------------------
[2010-02-11 09:14:24] chris dot dickinson at web dot de
Maybe the author wanted to write something like the following? :
<?php
if ($divisor == 0) {
trigger_error("Cannot divide by zero", E_USER_ERROR);
}
?>
or
<?php
if ( ! assert($divisor != 0)) {
trigger_error("Cannot divide by zero", E_USER_ERROR);
}
?>
------------------------------------------------------------------------
[2010-02-11 08:31:34] chris dot dickinson at web dot de
Description:
------------
Hi,
On your page http://ch2.php.net/manual/en/function.trigger-error.php
you give only this example
<?php
if (assert($divisor == 0)) {
trigger_error("Cannot divide by zero", E_USER_ERROR);
}
?>
It seems badly chosen. If $divisor is 0 then the assertion succeeds,
when actually you would probably not want $divisor to be 0 (!). If
$divisor is anything else but 0, the assertion will fail and give you an
error message. I got: "Warning: assert() [function.assert]: Assertion
failed in ..."
Reproduce code:
---------------
---
From manual page: function.trigger-error#Examples
---
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=51010&edit=1