note 85311 added to function.print

From: Date: Mon, 25 Aug 2008 16:47:43 +0000
Subject: note 85311 added to function.print
Groups: php.notes 
Request: Send a blank email to php-notes+get-143810@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" 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 } ?> ---- 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/85311 Del: integrated -- https://master.php.net/note/delete/85311/integrated Del: useless -- https://master.php.net/note/delete/85311/useless Del: bad code -- https://master.php.net/note/delete/85311/bad+code Del: spam -- https://master.php.net/note/delete/85311/spam Del: non-english -- https://master.php.net/note/delete/85311/non-english Del: in docs -- https://master.php.net/note/delete/85311/in+docs Del: other reasons-- https://master.php.net/note/delete/85311 Reject -- https://master.php.net/note/reject/85311 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#143810) next »