note 54174 added to language.operators.logical
| From: | Serafina at osu1 dot php dot net | Date: | Sun, 26 Jun 2005 05:06:18 +0000 |
| Subject: | note 54174 added to language.operators.logical | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-90955@lists.php.net to get a copy of this message | ||
Because the OR shorthand for an if block can produce more
readable code with less typing, it is tempting to produce functions that will return FALSE on
failure or some other data type on success. Like mysql_connect, which "Returns a MySQL link
identifier on success, or FALSE on failure."
The novice php php developer should avoid creating functions which might produce a FALSE on failure
and an integer on success, if there is any chance that the integer might be zero.
<?php
blah blah blah;
$i = give_me_liberty() or die("FATAL DB ERROR!");
blah blah blah;
?>
If the function give_me_liberty() occasionally completes successfully and produces a zero, the
result could be perplexing.
----
Manual Page -- http://www.php.net/manual/en/language.operators.logical.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54174
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54174&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54174&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54174&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54174&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54174&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54174&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54174&report=yes
Search -- http://master.php.net/manage/user-notes.php