note 55259 deleted from function.echo by nlopess

From: Date: Mon, 16 Jul 2007 18:01:13 +0000
Subject: note 55259 deleted from function.echo by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-128620@lists.php.net to get a copy of this message
Note Submitter: lorenpr at gmail dot com ---- 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.

« previous php.notes (#128620) next »