Re: green bean question on singleton php5

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




That very much make sense. I am indeed doing two assignments. I was just wondering how to call the constructor. The new statement was the only way I saw.... and it only worked in an assignment ..... I could not call dbaccess(); nor dbaccess::dbaccess();...


Probably the easiest way is a mix of the solutions.

Have an emtpy private constructor, and have the an init fucntion do the work so typing does not get mixed up.

Thanks.




Colin Guthrie wrote:
Julian wrote:
but that forces me to implement a large interface of functions that I
prefer to avoid...

the $dummy thing works... but I guess it is not "by the book".

I would like to understand what am I missing fom the concept....

You made a critial error in the original implem.

You effectively write dbaccess::$db twice.

Your $dummy gets around this.

See my previous post, but the real issue is this code flow:

In GetDb() you do:

dbaccess::$db= new dbaccess();

So firstly PHP creates calls the constructor.

In the constructor of dbaccess you do:
dbaccess::$db = new mysqli(...);

So PHP will assign the mysqli object to the variable you want.

PHP will then return from the contructor of dbaccess returning the
dbaccess object itself, which is then assigned to dbaccess::$db,
overwriting the mysqli object.

Hope that explains why what you did was a bit wrong and that one of the
solutions I proposed is what you want.

Col

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux