Re: About Classes and Scope
| From: | Phillip Jackson | Date: | Wed, 18 Feb 2004 16:12:44 +0000 |
| Subject: | Re: About Classes and Scope | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-178126@lists.php.net to get a copy of this message | ||
ummmm NOPE...
i don't believe that nick was looking for a constant - which cannot be
changed once defined.
there are a few ways to do this - for one, you can declare $var global
inside of the function in your class:
class myclass{
function myclass(){
global $var;
//do some stuff
}
}
when you invoke a class instance with a function that shares the same name
as the calling class it executes automatically. by declaring this $var
global it should be accessible to the rest of the functions.
another way to do this without declaring the $var as a global is to pass it
to the function explicitly:
function myclass($var){
//do stuff with $var
}
~Phillip Jackson
"Nick Wilson" <nick@stylesheet.org> wrote in message
news:20040218093115.GA24334@stylesheet.org...
>
> * and then Nick Wilson declared....
> > <?php
> > $myconfig=TRUE;
> >
> > class myclass {
> >
> > if($myconfig) {
> > var $something=1;
> > }
> > }
> >
> > I know that that is not the way it should be done though. What is the
> > best way to do this?
>
> On a hunch, i think i've found the answer:
> http://www.php.net/manual/en/language.constants.php
>
> Right?
>
> --
> Nick W