class Employee
{
public static $favSport = "Football";
public static function watchTV()
{
echo "Watching ".static::$favSport;
}
}
class Executive extends Employee
{
public static $favSport = "Polo";
}
echo Executive::watchTV();
Parse error: syntax error, unexpected T_STATIC on line 7
Why do I get parse error & and how to fix it? Thanks!
The best way to solve it is to remove the recently added plugins by disabling them. The WordPress site is also likely to generate an error after a code edit. A mistake as simple as a missing comma is enough to disrupt the function of a website.
Syntax Error – This error is caused by an error in the PHP structure when a character is missing or added that shouldn't be there. Unexpected – This means the code is missing a character and PHP reaches the end of the file without finding what it's looking for.
Ending thoughts on WordPress parse error Often it's due to a plugin or a theme. By deactivating the plugin/theme, you should be able to resolve the issue. The error message could also indicate a mistake in the code. Most of the time, it's necessary to track the faulty line and modify it.
Parse Error (Syntax) Parse errors are caused by misused or missing symbols in a syntax. The compiler catches the error and terminates the script. Parse errors are caused by: Unclosed brackets or quotes. Missing or extra semicolons or parentheses.
The parse error here:
echo "Watching ".static::$favSport;
is because late static bindings were introduced in PHP v5.3. Your php version (<5.3) doesn't recognize static::$favSport
.
There isn't any way I can think of to fix it for PHP older than 5.3, other than with object inheritance (which isn't really a fix per se since it doesn't have anything to do with static
)...
I had the same problem, but i used self in the place of static for my php version that's 5.2.1 well older than 5.3 http://php.net/manual/en/language.oop5.late-static-bindings.php
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