#49679 [Opn->Bgs]: Suggestion: addition of inequalities example to switch docs

From: Date: Fri, 02 Oct 2009 20:32:59 +0000
Subject: #49679 [Opn->Bgs]: Suggestion: addition of inequalities example to switch docs
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-2871@lists.php.net to get a copy of this message
ID: 49679 Updated by: fa@php.net Reported By: matt at plasmacoustics dot com -Status: Open +Status: Bogus Bug Type: Documentation problem PHP Version: Irrelevant New Comment: Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. "Note: Note that switch/case does loose comparision." Previous Comments: ------------------------------------------------------------------------ [2009-09-26 06:48:14] matt at plasmacoustics dot com Description: ------------ I feel the SWITCH documentation might best include code for dealing with inequalities in a CASE, using switch(TRUE). People are posting User Notes with implementations relying on type conversion of a random number to boolean TRUE, as the switch argument. This will cause a confusing logic error any time the argument is zero. Here's an example to help people get the right idea: Reproduce code: --------------- <?php $rand=rand(-3,+3); // Good use of switch() with inequalities: note TRUE is the argument, and all rand() outcomes are covered without overlap switch(TRUE) { case $rand < 0: print "$rand is less than zero"; break; case $rand == 0: print "$rand is equal to zero"; break; case $rand > 0: print "$rand is greater than zero"; break; } ?> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=49679&edit=1

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