note 11883 added to language.expressions.php
| From: | yasuo_ohgaki at hotmail dot com | Date: | Mon, 12 Mar 2001 04:14:08 +0000 |
| Subject: | note 11883 added to language.expressions.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-12284@lists.php.net to get a copy of this message | ||
[To editors:
Could you please delete my previous 2 notes? I think this notes would be just enough. Thank you]
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/en/language.expressions.php