On Tue, 05 May 2009 14:13:23 -0400, [email protected] (Robert Cummings)
wrote:
>On Tue, 2009-05-05 at 13:56 -0400, Tom Worster wrote:
>> there's a control structure i wish php had: a simple block that you can
>> ...........
>But PHP 5.3 introduces goto:
>
><?php
>
>header:
>
> if( $something ) ...
>
> goto body;
>
>body:
>
> if( $soemthingElse ) ...
> goto footer;
>
> if( $seomthingerElse ) ...
>
> goto footer;
>
>footer:
>
> // blah blah blah
> goto done;
>
>done;
I heartily agree. In my opinion 'break' is like a 'goto' without a label. As I
used to
tell my students "if I say 'break' the one thing I can be sure of is that you
will all
disappear. I had no idea where most of you go, or what you do, and I'm not even
sure if
I'll ever see some of you again."
'Goto' makes it possible to set up the more complex control sequences you
sometimes need,
yet have them clearly defined. For example:
<?php
begin: .......
if ( ... ) { goto error; }
.......
if ( .... ) { goto footer; }
.......
goto body;
repeat: ....
if ( .... ) { goto footer; }
.......
if ( ... ) { goto error; }
body: .........
if ($error) { goto error; }
........
if (!$error) { goto footer; }
error: ........
footer: ........
if ( .... ) { goto repeat; }
?>
I find it very difficult to set up sequences like this using if/else if (or
switches, but
I don't like them anyway), and have to resort to setting flags and very careful
indentation to make sure that I'm doing what I intended. Unfortunately my
provider is
still using PHP 4.something, and I have been too busy to switch to someone more
up-to-date.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php