note 85310 added to function.print
| From: | user at example dot net | Date: | Mon, 25 Aug 2008 16:45:55 +0000 |
| Subject: | note 85310 added to function.print | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143809@lists.php.net to get a copy of this message | ||
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" had 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" had been printed
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 89.166.158.179
----
Manual Page -- http://www.php.net/manual/en/function.print.php
Edit -- https://master.php.net/note/edit/85310
Del: integrated -- https://master.php.net/note/delete/85310/integrated
Del: useless -- https://master.php.net/note/delete/85310/useless
Del: bad code -- https://master.php.net/note/delete/85310/bad+code
Del: spam -- https://master.php.net/note/delete/85310/spam
Del: non-english -- https://master.php.net/note/delete/85310/non-english
Del: in docs -- https://master.php.net/note/delete/85310/in+docs
Del: other reasons-- https://master.php.net/note/delete/85310
Reject -- https://master.php.net/note/reject/85310
Search -- https://master.php.net/manage/user-notes.php