Forum Moderators: coopster

Message Too Old, No Replies

When php behaves like VB!

I had no idea goto's were useable here

         

Matthew1980

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

WebmasterWorld Senior Member 10+ Year Member



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

bkeep

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

10+ Year Member



goto is added in in PHP 5.3.x

Alcoholico

4:46 pm on Nov 27, 2010 (gmt 0)

10+ Year Member



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....

Matthew1980

5:14 pm on Nov 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>>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

Readie

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

WebmasterWorld Senior Member 10+ Year Member



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 :)

Matthew1980

6:04 pm on Dec 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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

Something different, I thought it was quite novel really.

Cheers,
MRb