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?
How To Fix parse error syntax error unexpected ' ' in wordpress Via FTP? In order to fix the Syntax Error in WordPress you need to edit the code that caused this error. The only possible way to resolve the syntax error is to directly exchange the faulty code via FTP or access the file you last edited using FTP.
A parse error: syntax error, unexpected appears when the PHP interpreter detects a missing element. Most of the time, it is caused by a missing curly bracket “}”. To solve this, it will require you to scan the entire file to find the source of the error.
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.
PHP constants are not variables, so you don't use isset
or empty
to check them.
Instead, you can use defined
:
defined('SCRIPT_URL')
to return a boolean if the field as been defined, then if it is, do a standard comparison on the value to check if it is truthy.
It's also worth noting (for future reference) that isset
is not a regular function; it is a "language construct" and cannot be used on anything besides variables (i.e. can't be used on the return value of a function). Same with empty
up until PHP 5.5.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With