Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is : in php?

Tags:

php

I made an error in my routes.php in laravel and typed : instead of ::

Route:get('about','PagesController@about');
Route:get('contact','PagesController@contact');

and I got an error message Label 'Route' already defined

Just curious what this means...

like image 276
orestiss Avatar asked Sep 16 '15 15:09

orestiss


Video Answer


1 Answers

You've discovered labels! They are a largely outdated and generally discouraged language construct that allows jumping around code via goto statements, as well as some others depending on language.

Example:

if (!array_key_exists('data', $_GET)) { goto hell; }
echo $_GET['data'] . " is the data I received.";

hell:
die("Erorr. . . or we finished. Who knows?");

There's some (semi-legitimate) functionality that can be implemented however. That said, still not a good practice:

for ($i = 0; $i < 999; $i++) {
  for ($j = 0; $j < 999; $j++) {
    for ($k = 0; $k < 999; $k++) {
      if ($someCondition)
        goto EndOfAllTheLoops; //Look, we broke out of ALL three loops!
    }
  }
}

EndOfAllTheLoops:
echo "We made it out!"

See PHP docs: http://php.net/manual/en/control-structures.goto.php

like image 84
CollinD Avatar answered Nov 04 '22 22:11

CollinD