Welcome to WebmasterWorld Guest from 18.204.48.199

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

When php behaves like VB!

I had no idea goto's were useable here

     
11:16 am on Nov 27, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 22, 2009
posts:1397
votes: 0


Hi all,

I have been php'ing for years now, but only discovered yesterday that I can use some VB syntax within php, only to find out as it's a well known control structure in a few languages. I say VB because that is the other language I use most:-
<?php
error_reporting(E_ALL|E_STRICT|E_DEPRECATED);

$a = "bar";

if($a == "foo"){
goto first_one;
}
else{
goto second_one;
}


first_one:

echo "this is foo";

exit;

second_one:

echo "this is bar";

exit;
?>

I could have some fun with this!

Just thought I would share what I found!

Cheers,
MRb
4:39 pm on Nov 27, 2010 (gmt 0)

Full Member

10+ Year Member

joined:June 1, 2007
posts:201
votes: 0


goto is added in in PHP 5.3.x
4:46 pm on Nov 27, 2010 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 14, 2006
posts:172
votes: 0


Great finding! I used to do some nifty stuff using GOTO on DOS GWBASIC.
The goto operator is available as of PHP 5.3.

[uk.php.net...] Don't miss the cartoon on that page about goto's usage....
5:14 pm on Nov 27, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 22, 2009
posts:1397
votes: 0


>>Don't miss the cartoon on that page about goto's usage....

xkcd - many of those adorn my office (partitioning) wall.. :)

Honestly, I hadn't known I could use it, purely by accident I found this.

Cheers,
MRb
12:19 am on Nov 28, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Dec 13, 2009
posts:945
votes: 0


I chanced upon this a few months back, the comic on the php.net page on it is pretty cool :)

Back on topic though, however much it is frowned upon as "bad practice" it's apparently no slower than plain old procedural code.

Although to be honest, I avoid using it :)
6:04 pm on Dec 10, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 22, 2009
posts:1397
votes: 0


>>Although to be honest, I avoid using it :)

Something different, I thought it was quite novel really.

Cheers,
MRb