This is a very weird situation like I've never seen in my life. For some reason PHP is ignoring a lot of code inside a static function.
Here is the example:
static function describe($tableName, $columns = '*') {
var_dump($tableName);
die();
$md5 = ...code...
if (!empty($content = Cache::get($md5))) {
return unserialize($content);
}
I keep getting the error
Parse error: syntax error, unexpected '=', expecting ')'
in
if (!empty($content = Cache::get($md5))) {
And yes it recognises the class Cache
and its function.
Can anyone guide me?
Prior to PHP 5.5, empty()
function can only support strings.
Any other input provided to it like: a function call e.g.
if (empty(myfunction()) {
// ...
}
would result parse error.
As per documentation:
Note: Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error. In other words, the following will not work: empty(trim($name)). Instead, use trim($name) == false.
Better way, get your $content
variable first and then check if it is not empty.
Rather than initialising it and checking its emptiness simultaneously.
You can separate the if
statement in two parts like this:
if ($content = Cache::get($md5) && !empty($content)) {
return unserialize($content);
}
Try this,
if (!empty($content) && $content = Cache::get($md5)) {
return unserialize($content);
}
OR : To get easy readability
if (!empty($content){
if($content = Cache::get($md5)){
return unserialize($content);
}
}
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