note 55259 added to function.echo

From: Date: Thu, 28 Jul 2005 17:17:37 +0000
Subject: note 55259 added to function.echo
Groups: php.notes 
Request: Send a blank email to php-notes+get-92657@lists.php.net to get a copy of this message
I just want to point out something to beginners. The documentation is misleading where it says: // Because echo is not a function, following code is invalid. ($some_var) ? echo 'true' : echo 'false'; The code is invalid, but not because 'echo' is a language construct, but rather because 'echo' does not return a value. So don't be mislead: the syntax used above is certainly not limited to functions. You must keep in mind that the job of the ternary syntax used is not actually to display anything, but to test a boolean relationship. The 'print' statement would work because it always returns a 1, which in php, is interpreted to a boolean 'true'. Things that return 'void' cannot be expected to evaluate to a 'true' or 'false', and that is why using 'echo' in this particular case is invalid. ---- Submitter IP: 64.71.164.2 ---- Manual Page -- http://www.php.net/manual/en/function.echo.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55259 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55259&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55259&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55259&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55259&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55259&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55259&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55259&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92657) next »