|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-05-07 11:52 UTC] php at hristov dot com
Description:
------------
In the following case the parser bails out:
php -r 'echo true? $t++,"true":"false";'
with
Parse error: syntax error, unexpected ',' in Command line code on line 1
The following mini-C program however does compile, although gcc is kind of stupid to realize that there should be no warning:
#include <stdio.h>
int main(void)
{
int t=0, f=0;
printf("%s\n", (1==1) ? t++,"True":"False");
}
andrey@whirlpool:~/dev> gcc -o a a.c
andrey@whirlpool:~/dev> ./a
True
The comma does work however when used in a for() loop :
andrey@whirlpool:~/dev> php -r 'for($i=0; $a++, $i < 2; $i++) echo "-"; echo "\n";'
--
Reproduce code:
---------------
php -r 'echo true? $t++,"true":"false";'
Expected result:
----------------
true
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 08:00:02 2025 UTC |
To make it even easier for testing : ./php -r '$a=1; $b = ($a, 2);' The equivalent in C is: #include <stdio.h> int main(void) { int a = 1, c; c = (a, 2); printf("%d\n", c); } "," has lower prio than =, thus the brackets.