note 106323 modified in control-structures.goto by danbrown
| From: | danbrown@php.net | Date: | Thu, 27 Oct 2011 14:01:43 +0000 |
| Subject: | note 106323 modified in control-structures.goto by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-184173@lists.php.net to get a copy of this message | ||
You cannot implement a Fortran-style "computed GOTO" in PHP because the label cannot be a
variable. See: http://en.wikipedia.org/wiki/Considered_harmful
<?php // RAY_goto.php
error_reporting(E_ALL);
// DEMONSTRATE THAT THE GOTO LABEL IS CASE-SENSITIVE
goto a;
echo 'Foo';
a: echo 'Bar';
goto A;
echo 'Foo';
A: echo 'Baz';
// CAN THE GOTO LABEL BE A VARIABLE?
$a = 'abc';
goto $a; // NOPE: PARSE ERROR
echo 'Foo';
abc: echo 'Boom';
?>
--was--
You cannot implement a Fortran-style "computed GOTO" in PHP because the label cannot be a
variable. See: http://en.wikipedia.org/wiki/Considered_harmful
<?php // RAY_goto.php
error_reporting(E_ALL);
// DEMONSTRATE THAT THE GOTO LABEL IS CASE-SENSITIVE
goto a;
echo 'Foo';
a: echo 'Bar';
goto A;
echo 'Foo';
A: echo 'Baz';
// CAN THE GOTO LABEL BE A VARIABLE?
$a = 'abc';
goto $a; // NOPE: PARSE ERROR
echo 'Foo';
abc: echo 'Boom';
http://php.net/manual/en/control-structures.goto.php