php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #51010 Bad example
Submitted: 2010-02-11 08:31 UTC Modified: 2010-02-11 11:08 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: chris dot dickinson at web dot de Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: chris dot dickinson at web dot de
New email:
PHP Version: OS:

 

 [2010-02-11 08:31 UTC] 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
---



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-02-11 09:14 UTC] 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 11:06 UTC] 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 11:08 UTC] 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:08 UTC] rquadling@php.net
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.
 [2020-02-07 06:09 UTC] phpdocbot@php.net
Automatic comment on behalf of rquadling
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=27865e7aa2ec7095eac2e22e42c167869fb65fc7
Log: Simplified example. Fix #51010
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 09:00:02 2026 UTC