php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15866 using echo for expression 3 in for loop creates parse error
Submitted: 2002-03-04 23:31 UTC Modified: 2002-03-05 01:44 UTC
From: chunky_ at hotmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.0.6 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: chunky_ at hotmail dot com
New email:
PHP Version: OS:

 

 [2002-03-04 23:31 UTC] chunky_ at hotmail dot com
Using Echo in expression 3 of a for loop creates a parse error.

For instance:

$blah = (0,1,2,3,4,5,6,7,8,9);
for ($i = 0; $i < 10; echo $blah[$i++]);

results in this error:

Parse error: parse error, expecting `')'' in /home/chunky/public_html/test.php on line XX (line of for loop)

However, this will parse properly:

$blah = (0,1,2,3,4,5,6,7,8,9);
for ($i = 0; $i < 10; print $blah[$i++]);

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-05 00:19 UTC] mfischer@php.net
I've found such differences some time ago (but didn't care about it yet).

E.g.

<? $a = (echo "test\n"); var_dump($a); ?>  <-- parser error
<? $a = (print "test\n"); var_dump($a); ?> <-- outputs 1

'print' always evals to int(1)
 [2002-03-05 00:22 UTC] mfischer@php.net
The last sentence if wrong. print actually returns a value (as stated in the manual), maybe that's the difference.
 [2002-03-05 01:29 UTC] derick@php.net
echo is a language construct and not a function. It's different this way from print which is a function (a built-in one).
Not a bug -> Bogus

Derick
 [2002-03-05 01:44 UTC] mfischer@php.net
The something else is bogus too. From the manual:

echo() is not actually a function (it is a language construct) ...

and

print() is not actually a function (it is a language construct) ....

So the phrase "is a language construct" alone doesn't weight much. There *is* a difference, but it's not the 'being a language construct'.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jun 27 04:01:35 2025 UTC