#51010 [Opn->Csd]: Bad example

From: Date: Thu, 11 Feb 2010 11:08:50 +0000
Subject: #51010 [Opn->Csd]: Bad example
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-3868@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 +Status: Closed Bug Type: Documentation problem PHP Version: Irrelevant New Comment: This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. Previous Comments: ------------------------------------------------------------------------ [2010-02-11 11:08:45] svn@php.net Automatic comment from SVN on behalf of rquadling Revision: http://svn.php.net/viewvc/?view=revision&revision=294879 Log: Simplified example. Fix #51010 ------------------------------------------------------------------------ [2010-02-11 11:06:20] rquadling@php.net 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. ------------------------------------------------------------------------ [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

« previous php.doc.bugs (#3868) next »