Re: static not working as expected
| From: | Purushotham Komaravolu | Date: | Tue, 18 Jun 2002 17:57:24 +0000 |
| Subject: | Re: static not working as expected | ||
| References: | 1 2 | Groups: | php.dev php.general |
| Request: | Send a blank email to php-general+get-102746@lists.php.net to get a copy of this message | ||
Thanks for your prompt answer.If that's the case then, how do I define a
singleton class?
Regards,
Puru
----- Original Message -----
From: "Markus Fischer" <mfischer@guru.josefine.at>
To: "Purushotham Komaravolu" <purikk@hotmail.com>
Cc: <php-dev@lists.php.net>; <php-general@lists.php.net>
Sent: Tuesday, June 18, 2002 10:58 AM
Subject: Re: [PHP-DEV] static not working as expected
> 'statis' is ONLY used inside functions. You need the 'var'
> keyword to define class property. This is true for ZE1, I
> can't tell if ZE2 has static class properties, anyone else?
>
> - Markus
>
> On Tue, Jun 18, 2002 at 10:42:43AM -0700, Purushotham Komaravolu wrote :
> > <?php
> >
> > class Counter {
> > var $counter = 0;
> >
> > function increment_and_print()
> > {
> > print ++$this->counter;
> > print "\n";
> > }
> > }
> >
> >
> > class SingletonCounter {
> > static $m_instance = NULL; // throwing error here
> >
> > function Instance()
> > {
> > if (self::$m_instance == NULL) {
> > self::$m_instance = new Counter();
> > }
> > return self::$m_instance;
> > }
> > }
> >
> > SingletonCounter::Instance()->increment_and_print();
> > SingletonCounter::Instance()->increment_and_print();
> > SingletonCounter::Instance()->increment_and_print();
> >
> > ?>
> >
> >
> > is throwing the following error
> > Parse error: parse error, expecting
T_OLD_FUNCTION' or
> > T_FUNCTION' or
T_VAR' or '}'' in /singleton.php on line 15
>
> --
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, visit: http://www.php.net/unsub.php
>