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;
}
}
<?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;
}
}
Try that. You had an extra bracket.
The error was actually in the line function __construct()
. It created a function and then an empty set of brackets (doesn't actually error).
Then, you never ended up breaking out of the construct function so it error-ed when you tried to use the public parameter inside a function, which is not valid syntax.
This is why we make consistent bracket placement, so we always put stuff in the same place, and thus can easily spot mis-placements.
In other words, you have a syntax error:
function __construct() { <-- note the extra open curly
{ <-- note the extra open curly
I had the same Problem and then i found out that the curly braces "{" of my class was missing .
精彩评论