I am getting this unfamiliar error when running the code bellow. I can’t see what’s wrong.
Error:
Parse error: syntax error, unexpected ‘{‘ in /var/www/crawler/sources.php on line 2
<?php
sourcelist($filename = '/var/resources/sources.list'){
if (is_readable($filename)){
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
return(json_decode($contents));
} else {
return NULL;
}
}
print_r(sourcesList());
?>
This is the exact code snippet I run. What’s wrong?
You’re trying to define a function, but you’ve missed out the
functionkeyword:should be
See the documentation on PHP functions.