Click to See Complete Forum and Search --> : [RESOLVED] PHP 5.2.17 and Singleton classes


S.P.I.
May 12th, 2011, 03:59 AM
Hi there, I spent the last 5 days developing an authorization system making use of the singleton pattern for a few classes. The script works just fine on my local server (running a php 5.3 config) but on my clients server it crashes royally.

The error says:
T_STATIC expecting T_STRING,T_FUNCTION OR $

I understand that earlier versions of PHP (in this case, 5.2.17) seem to have some trouble with late binding. Do you think this is what's causing the problem? Would it work out if they upgraded to 5.3? Here's the code that flags the error:



class session extends login{
private $fingerprint;
public static $s_instance = NULL;



private function __construct(){;}


public static function s_getinstance()
{
if (!isset(static::$s_instance)){
$c = __CLASS__;
static::$s_instance = new $c;
}
return static::$s_instance;


}

.... *code continues*




Also, what is the deal with the following mysql error:
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)"

Can this be flagged if I insert the incorrect hostname,username, password or dbname?

Thank you.

S.P.I.
May 12th, 2011, 05:28 AM
I have resolved the issue regarding the mysql socket error. Apparently if you specify the hostname as 'localhost' mysql automatically initializes a UNIX socket.

http://dev.mysql.com/doc/refman/5.0/en/can-not-connect-to-server.html

I still have a few questions about the usage of the static keyword. Replacing static with self in circumstances such as this once (static::$conn---replaced---- self::$conn) fixes the issue. I think php 5.2 doesn't work too well with the static keyword and requires explicit wording. Just my 2 cents. I am not sure if I am even close to the right answer though.