Posted by Joe Molloy on 11/03/05 21:22
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]
|