Troubleshoot with unexpected T_PUBLIC error

I get this error ...

Parse error: syntax error, unexpected T_PUBLIC in C: \ filename here on line 12

On this line ....

public static function getInstance(){ 

The code...

 <?PHP class Session{ private static $instance; function __construct() { { session_start(); echo 'Session object created<BR><BR>'; } public static function getInstance(){ if (!self::$instance) { self::$instance = new Session(); } return self::$instance; } } 
+4
source share
3 answers
 <?PHP class Session{ private static $instance; function __construct() { session_start(); echo 'Session object created<BR><BR>'; } public static function getInstance() { if (!self::$instance) { self::$instance = new Session(); } return self::$instance; } } 

Give it a try. You had an additional bracket.

The error was in the line function __construct() . He created a function and then an empty set of brackets (this is actually not an error).

Then you never stopped working on the design, so you fixed the error when trying to use an open parameter inside a function, which is invalid syntax.

This is why we make consistent placements in brackets, so we always put things in the same place and, therefore, we can easily find the wrong placements.

+9
source

In other words, you have a syntax error:

 function __construct() { <-- note the extra open curly { <-- note the extra open curly 
+2
source

I had the same problem and found out that the curly braces "{" of my class are missing.

+1
source

Source: https://habr.com/ru/post/1299062/


All Articles