Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <1996520.IoEltsQCmd@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Tue, 25 Feb 2014 01:37:26 +0100 User-Agent: KNode/4.11.5 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. <0.914eafe42061d70d7566.20140224044930GMT.87fvn9ru79.fsf@bsb.me.uk> <4293011.KJL4Tygh8x@PointedEars.de> <0.60537d4b87ccab3ac30a.20140224212551GMT.87ppmcqk2o.fsf@bsb.me.uk> <6171065.55Kx8BzDJ9@PointedEars.de> <530bdeb5$0$9519$9b4e6d93@newsspool1.arcor-online.net> MIME-Version: 1.0 Lines: 160 NNTP-Posting-Date: 25 Feb 2014 01:37:31 CET NNTP-Posting-Host: 4b64f6df.newsspool1.arcor-online.net X-Trace: DXC=H7I8cG<4i7k^Y=RbYBPl4`ic==]BZ:afn4Fo<]lROoRankgeX?EC@@`PmZQ?n;CHJeDZm8W4\YJNlYUVHKH;GI^g>8ZdD_1a;VhH@^\D] Thomas 'PointedEars' Lahn wrote: >> Ben Bacarisse wrote: >>> Thomas 'PointedEars' Lahn writes: >>>> Ben Bacarisse wrote: >>>>> […] Expressions are built from operators, but is ',' an operator in >>>>> [PHP? >>>>> It appears in the operator precedence table but it isn't an operator >>>>> in an sense that would normally be understood by someone familiar with >>>>> these terms. >>>> >>>> ECMAScript has a “Comma Operator”, too. >>> >>> But my point was the PHP doesn't have one -- >> >> But it does: >> >> for ($i = 0, $j = 42; $i < $j; ++$i); >> ^ > > The comma is used in sevaral places in the PHP grammar[1]. However, > IMHO your example (inside a for_expr) is the only case where the comma > is used as an operator. The other uses are for declaration and > parameter lists (spoken in a broad sense). I am aware of that. >>> not in any normal sense of the word. >> >> Please define what you consider to be an operator in a “normal sense of >> the word”. > > It might be defined as an operator that can be used in arbitrary > expressions. A speculation, one that is almost self-evidently false. Just consider the operators (including, but not just in, programming languages) that require their operands to be of a certain type. > Consider the following ECMAScript expression: > > a = 1, b = 2; > > The "equivalent" expression in PHP is a syntax error: > > $a = 1, $b = 2; I am aware of that. >>> ECMAScript really does have one (like C and C++ do). >> >> Why do you think C and C++ have a comma operator (like ECMAScript)? > > According to the C grammar[2]: > > exp : assignment_exp > | exp ',' assignment_exp > > [1] > [2] ACK; I stand corrected. For reasons I cannot explain (probably it is just late), I had assumed that the comma operator in ECMAScript also worked with assignments, and this is what I tested with C and C++: $ cat foo.c #include int main() { int x = 42, 23; printf("%i\n", x); return 0; } $ gcc -Wall -o foo.out foo.c foo.c: In function ‘main’: foo.c:4:15: error: expected identifier or ‘(’ before numeric constant int x = 42, 23; ^ $ cat foo.cpp #include using namespace std; int main() { int x = 42, 23; cout << x << endl; return 0; } $ g++ -Wall -o foo.out foo.cpp 2>&1| tee /tmp/v6wTKDF/0 foo.cpp: In function ‘int main()’: foo.cpp:5:15: error: expected unqualified-id before numeric constant int x = 42, 23; ^ However, in ECMAScript: | >>> var x = 42, 23; | SyntaxError: Unexpected number What I meant instead was | >>> 42, 23 | 23 which does work like that in certain contexts in C and C++, but not in PHP: $ cat foo.c #include int main() { printf("%i\n", (42, 23)); return 0; } $ gcc -Wall -o foo.out foo.c 2>&1| tee /tmp/vJ0RqVR/0 foo.c: In function ‘main’: foo.c:4:21: warning: left-hand operand of comma expression has no effect [-Wunused-value] printf("%i\n", (42, 23)); ^ $ ./foo.out 23 $ cat foo.cpp #include using namespace std; int main() { cout << (42, 23) << endl; return 0; } $ g++ -Wall -o foo.out foo.cpp foo.cpp: In function ‘int main()’: foo.cpp:5:16: warning: left operand of comma operator has no effect [-Wunused-value] cout << (42, 23) << endl; ^ $ ./foo.out 23 $ php -r 'echo (42, 23) . "\n";' PHP Parse error: syntax error, unexpected ',' in Command line code on line 1 [Interesting that gcc says “operand” and “comma *expression*”, while g++ says “operand” and “comma *operator*”.] PointedEars -- Sometimes, what you learn is wrong. If those wrong ideas are close to the root of the knowledge tree you build on a particular subject, pruning the bad branches can sometimes cause the whole tree to collapse. -- Mike Duffy in cljs,