Re: [PHP] green bean question on singleton php5

2008-01-16 Thread Eric Butera
On Jan 16, 2008 5:10 PM, Nathan Nobbe <[EMAIL PROTECTED]> wrote: > On Jan 16, 2008 5:09 PM, Eric Butera <[EMAIL PROTECTED]> wrote: > > > Here is an implementation: > > http://framework.zend.com/manual/en/zend.registry.html > > > > Here is another: > > > http://www.stubbles.net/browser/trunk/src/mai

Re: [PHP] green bean question on singleton php5

2008-01-16 Thread Jochem Maas
Eric Butera schreef: On Jan 16, 2008 4:55 PM, Jochem Maas <[EMAIL PROTECTED]> wrote: Eric Butera schreef: On Jan 16, 2008 4:13 PM, Nathan Nobbe <[EMAIL PROTECTED]> wrote: On Jan 16, 2008 3:59 PM, Jochem Maas <[EMAIL PROTECTED]> wrote: given that dbaccess doesn't extend mysqli instantiation

Re: [PHP] green bean question on singleton php5

2008-01-16 Thread Nathan Nobbe
On Jan 16, 2008 5:09 PM, Eric Butera <[EMAIL PROTECTED]> wrote: > Here is an implementation: > http://framework.zend.com/manual/en/zend.registry.html > > Here is another: > > http://www.stubbles.net/browser/trunk/src/main/php/net/stubbles/util/stubRegistry.php > cool; ill have a look when i get

Re: [PHP] green bean question on singleton php5

2008-01-16 Thread Eric Butera
On Jan 16, 2008 5:06 PM, Nathan Nobbe <[EMAIL PROTECTED]> wrote: > On Jan 16, 2008 4:55 PM, Jochem Maas <[EMAIL PROTECTED]> wrote: > > > Eric Butera schreef: > > > > > > > > > > > I still don't understand the obsession of a singleton in regards to a > > > db connection. Using a registry is a much

Re: [PHP] green bean question on singleton php5

2008-01-16 Thread Nathan Nobbe
On Jan 16, 2008 5:06 PM, Eric Butera <[EMAIL PROTECTED]> wrote: > Also with the registry you can use lazy loading. singleton is typically implemented with a lazy loading approach, and most of the code samples ive seen on this thread today use a lazy loading approach. could you give us a more co

Re: [PHP] green bean question on singleton php5

2008-01-16 Thread Nathan Nobbe
On Jan 16, 2008 4:55 PM, Jochem Maas <[EMAIL PROTECTED]> wrote: > Eric Butera schreef: > > I still don't understand the obsession of a singleton in regards to a > > db connection. Using a registry is a much better practice I think. > > > > I think I alluded to the registry pattern in my reply abo

Re: [PHP] green bean question on singleton php5

2008-01-16 Thread Eric Butera
On Jan 16, 2008 4:55 PM, Jochem Maas <[EMAIL PROTECTED]> wrote: > Eric Butera schreef: > > > On Jan 16, 2008 4:13 PM, Nathan Nobbe <[EMAIL PROTECTED]> wrote: > >> On Jan 16, 2008 3:59 PM, Jochem Maas <[EMAIL PROTECTED]> wrote: > >> > >>> given that dbaccess doesn't extend mysqli instantiation of db

Re: [PHP] green bean question on singleton php5

2008-01-16 Thread Jochem Maas
Eric Butera schreef: On Jan 16, 2008 4:13 PM, Nathan Nobbe <[EMAIL PROTECTED]> wrote: On Jan 16, 2008 3:59 PM, Jochem Maas <[EMAIL PROTECTED]> wrote: given that dbaccess doesn't extend mysqli instantiation of dbaccess is completely pointless no? i dont know; i think using an instance of dbac

Re: [PHP] green bean question on singleton php5

2008-01-16 Thread Eric Butera
On Jan 16, 2008 4:13 PM, Nathan Nobbe <[EMAIL PROTECTED]> wrote: > On Jan 16, 2008 3:59 PM, Jochem Maas <[EMAIL PROTECTED]> wrote: > > > given that dbaccess doesn't extend mysqli instantiation of dbaccess is > > completely > > pointless no? > > > i dont know; i think using an instance of dbaccess t

Re: [PHP] green bean question on singleton php5

2008-01-16 Thread Nathan Nobbe
On Jan 16, 2008 3:59 PM, Jochem Maas <[EMAIL PROTECTED]> wrote: > given that dbaccess doesn't extend mysqli instantiation of dbaccess is > completely > pointless no? i dont know; i think using an instance of dbaccess to control a single instance of the mysqli class is appropriate. personally, i

Re: [PHP] green bean question on singleton php5

2008-01-16 Thread Jochem Maas
julian schreef: you are forcing the no instantiation via abstract, instead of hiding via private method constructor. you want to garantee a single instance of the mysqli object - who cares exactly how this is done. besides which the whole exercise is bogus. you want a DB connection abstractio

Re: [PHP] green bean question on singleton php5

2008-01-16 Thread julian
you are forcing the no instantiation via abstract, instead of hiding via private method constructor. You change the constructor for an init function. still the $dummy = new dbaccess (). looks like a simpler solution Thanks for your comments Jochem Maas wrote: julian schreef: H

RE: [PHP] green bean question on singleton php5

2008-01-16 Thread Andrés Robinet
> -Original Message- > From: Julian [mailto:[EMAIL PROTECTED] > Sent: Wednesday, January 16, 2008 3:39 PM > Cc: php-general@lists.php.net > Subject: Re: [PHP] green bean question on singleton php5 > > > nope... only works if I change > > $dummy= new dbac

Re: [PHP] green bean question on singleton php5

2008-01-16 Thread Nathan Nobbe
On Jan 16, 2008 1:36 PM, Julian <[EMAIL PROTECTED]> wrote: > I would like to understand what am I missing fom the concept here are the issues i see; you should have a private static for the instance of dbaccess you should have a private instance variable for the instance of the mysqli class

Re: [PHP] green bean question on singleton php5

2008-01-16 Thread Jochem Maas
julian schreef: Hi, I am implementing this try comparing this rewrite with your version: abstract class dbaccess { static $db = null; private static function init() { if (dbaccess::$db)) return; dbaccess::$db = new mysqli("localhost",USER,PASSWD,DB); if(mysqli_con

RE: [PHP] green bean question on singleton php5

2008-01-16 Thread Andrés Robinet
> -Original Message- > From: Julian [mailto:[EMAIL PROTECTED] > Sent: Wednesday, January 16, 2008 3:37 PM > To: Daniel Brown > Cc: julian; php-general@lists.php.net > Subject: Re: [PHP] green bean question on singleton php5 > > > but that forces me to imp

Re: [PHP] green bean question on singleton php5

2008-01-16 Thread Nathan Nobbe
to all who have posted classes w/ the singleton instance as a public static; this is not good. the singleton instance should be stored in a private static variable. why? because, otherwise client code can just access the value directly, and even unset the instance; which sort of defeats the purpos

Re: [PHP] green bean question on singleton php5

2008-01-16 Thread Julian
nope... only works if I change $dummy= new dbaccess(); and keep the rest . Thanks. ... hope it does not repeat... got undelivered... Eric Butera wrote: On Jan 16, 2008 12:57 PM, julian <[EMAIL PROTECTED]> wrote: Hi, I am implementing this class dbaccess{ static $db=null; st

Re: [PHP] green bean question on singleton php5

2008-01-16 Thread Julian
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 Thanks. JCG Daniel Brown wrote: On Jan 16, 2008 12:57 PM, julian <[EMAIL

Re: [PHP] green bean question on singleton php5

2008-01-16 Thread Daniel Brown
On Jan 16, 2008 12:57 PM, julian <[EMAIL PROTECTED]> wrote: > > > Hi, > > I am implementing this [snip!] I'm heading out to lunch, so double-check this for errors, but I rewrote your class. You'll have to add your fetch handlers and such. query(..); // Your query here. ?>

Re: [PHP] green bean question on singleton php5

2008-01-16 Thread Eric Butera
On Jan 16, 2008 12:57 PM, julian <[EMAIL PROTECTED]> wrote: > > > Hi, > > I am implementing this > > class dbaccess{ >static $db=null; >static $othervar=33; > >private function dbaccess(){ > dbaccess::$db= new mysqli("localhost",USER,PASSWD,DB); > if(mysqli_connect_errno()){