Search code examples
phpparse-error

lower-cased reserved keyword throws an error. Why?


I've got this function

//admin
$router->route['/admin']->route['default'] = function() { //line 51
    if (isLoggedIn())                                     //line 52
        goTo('CMS');                                      //line 53 <---
    else                                                  //and so on
        goTo('login');  
};

but I've a Parse error: syntax error, unexpected '(', expecting T_STRING in /path/index.php on line 53
What is the error?


Solution

  • goto is a reserved word. You can NOT override it, no matter how much you fiddle with upper-/lower-case variations:

    php > function goto() { echo 'foo'; }
    PHP Parse error:  syntax error, unexpected 'goto' (T_GOTO), expecting '(' in php shell code on line 1
    php > function goTo() { echo 'foo'; }
    PHP Parse error:  syntax error, unexpected 'goTo' (T_GOTO), expecting '(' in php shell code on line 1
    php > function GOTO() { echo 'foo'; }
    PHP Parse error:  syntax error, unexpected 'GOTO' (T_GOTO), expecting '(' in php shell code on line 1
    

    You should never have been able to define your goTo function in the first place.