note 11883 modified in language.expressions.php by jmcastagnetto

From: Date: Mon, 12 Mar 2001 09:43:10 +0000
Subject: note 11883 modified in language.expressions.php by jmcastagnetto
Groups: php.notes 
Request: Send a blank email to php-notes+get-12292@lists.php.net to get a copy of this message
Manual defines "expression is anything that has value", Therefore, parser will give error for following code. ($val) ? echo('true') : echo('false'); Note: "? : " operator has this syntax "expr ? expr : expr;" since echo does not have(return) value and ?: expects expression(value). However, if function/language constructs that have/return value, such as include(), parser compiles code. Note: User defined functions always have/return value without explicit return statement (returns NULL if there is no return statement). Therefore, user defined functions are always valid expressions. [It may be useful to have VOID as new type to prevent programmer to use function as RVALUE by mistake] For example, ($val) ? include('true.inc') : include('false.inc'); is valid, since "include" returns value. The fact "echo" does not return value(="echo" is not a expression), is less obvious to me. Print() and Echo() is NOT identical since print() has/returns value and can be a valid expression. http://www.php.net/manual/language.expressions.php.php

« previous php.notes (#12292) next »