note 85311 deleted from function.print by sobak
| From: | sobak@php.net | Date: | Sat, 10 Dec 2016 23:18:16 +0000 |
| Subject: | note 85311 deleted from function.print by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208463@lists.php.net to get a copy of this message | ||
Note Submitter: user at example dot net
----
Be careful when using print. Since print is a language construct and not a function, the parentheses
around the argument is not required.
In fact, using parentheses can cause confusion with the syntax of a function and SHOULD be omited.
Most would expect the following behavior:
<?php
if (print("foo") && print("bar")) {
// "foo" and "bar" have been printed
}
?>
But since the parenthesis around the argument are not required, they are interpretet as part of the
argument.
This means that the argument of the first print is
("foo") && print("bar")
and the argument of the second print is just
("bar")
For the expected behavior of the first example, you need to write:
<?php
if ((print "foo") && (print "bar")) {
// "foo" and "bar" have been printed
}
?>