Posted by Joe Molloy on 11/04/05 02:57
Thanks for all the tips - the $_GLOBALS function looks the most applicable
in my situation - I'm comming into some previously written code and don't
want to have to reinvent the wheel :)
Joe
"Joe Molloy" <molloy_joe@hotmail.com> wrote in message
news:Hrtaf.18148$R5.1241@news.indigo.ie...
> Hi,
>
> I'm wondering is there any way I can get a variable's value from within a
> class when the variable has been declared outside the class but in the
> same script as the class is contained in. For example, say I have the
> following script
>
> <?php
> constant myvar = "my original string";
>
> class myClass
> {
> function returnmyvar()
> {
> return "some processed text and ".$myvar;
> }
>
> function usesnewstr()
> {
> echo $this->returnmyvar();
> }
> }
>
> $myCls = &New myClass($myvar);
> $myCls -> usesnewstr();
> ?>
>
>
> Now what I'd like this to output would be:
> some processed text and my original string
> but all I get is:
> some processed text and
>
> Now I know I could make a constructor function and pass $myvar in that way
> but I would rather not have to do that as that would entail changing the
> instatiation statements whevever that class is already used. Any other
> ways to make $myvar visible to functions inside the class?
>
> Joe
>
>
Navigation:
[Reply to this message]
|