Parse Error: Unexpected Syntax Error ')', Expected :: (T_PAAMAYIM_NEKUDOTAYIM)

advertisements

This question already has an answer here:

  • Reference - What does this error mean in PHP? 30 answers

I have the following code

define("SCRIPT_URL", "");
function ifScriptFolder() {
    if(isset(SCRIPT_URL) && !empty(SCRIPT_URL)) {
        echo "/".SCRIPT_URL."/";
    } else {
        echo "/";
    }
}

but it's giving me the following error:

Parse error: syntax error, unexpected ')', expecting :: (T_PAAMAYIM_NEKUDOTAYIM) in *(path)* on line 3

Can anyone see what's going wrong here or how to fix it?


If you trying to determine if constant exists, then try to use defined() or constant(), not isset().


From php.net:

Function defined():

Returns TRUE if the named constant given by name has been defined, FALSE otherwise.

Function constant():

Returns the value of the constant, or NULL if the constant is not defined.


Fixed function:

function ifScriptFolder() {
    echo defined('SCRIPT_URL') ? "/" . constant('SCRIPT_URL') . "/" : "/"
}

UPD:

The defined() function is a better solution for this, because it will not emit E_WARNING if constant was not defined.