note 90327 added to language.expressions
| From: | MagnusDeininger at osu1 dot php dot net | Date: | Thu, 16 Apr 2009 15:04:29 +0000 |
| Subject: | note 90327 added to language.expressions | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-153393@lists.php.net to get a copy of this message | ||
Note that even though PHP borrows large portions of its syntax from C, the ',' is treated
quite differently. It's not possible to create combined expressions in PHP using the
comma-operator that C has, except in for() loops.
Example (parse error):
<?php
$a = 2, $b = 4;
echo $a."\n";
echo $b."\n";
?>
Example (works):
<?php
for ($a = 2, $b = 4; $a < 3; $a++)
{
echo $a."\n";
echo $b."\n";
}
?>
This is because PHP doesn't actually have a proper comma-operator, it's only supported as
syntactic sugar in for() loop headers. In C, it would have been perfectly legitimate to have this:
int f()
{
int a, b;
a = 2, b = 4;
return a;
}
or even this:
int g()
{
int a, b;
a = (2, b = 4);
return a;
}
In f(), a would have been set to 2, and b would have been set to 4.
In g(), (2, b = 4) would be a single expression which evaluates to 4, so both a and b would have
been set to 4.
----
Server IP: 217.160.72.57
Probable Submitter: 91.32.95.205
----
Manual Page -- http://www.php.net/manual/en/language.expressions.php
Edit -- https://master.php.net/note/edit/90327
Del: integrated -- https://master.php.net/note/delete/90327/integrated
Del: useless -- https://master.php.net/note/delete/90327/useless
Del: bad code -- https://master.php.net/note/delete/90327/bad+code
Del: spam -- https://master.php.net/note/delete/90327/spam
Del: non-english -- https://master.php.net/note/delete/90327/non-english
Del: in docs -- https://master.php.net/note/delete/90327/in+docs
Del: other reasons-- https://master.php.net/note/delete/90327
Reject -- https://master.php.net/note/reject/90327
Search -- https://master.php.net/manage/user-notes.php