Re: public and private parts in classes ?
| From: | Andrey Hristov | Date: | Tue, 25 Sep 2001 14:16:10 +0000 |
| Subject: | Re: public and private parts in classes ? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-68707@lists.php.net to get a copy of this message | ||
class Test {
function Test() {
$_this->foo = "bar";
}
}
$n = new Test;
echo "foo: " . $n->foo."\n";
var_dump($n);
returns :
foo:
object(test)(0) {
}
So there is no member variable which you meant to be private in the instance $n of class Test.
Have fun.
Andrey Hristov
IcyGEN Corporation
http://www.icygen.com
BALANCED SOLUTIONS
----- Original Message -----
From: "Nick Winfield" <pioneer@dac.org>
To: "Andrey Hristov" <ahristov@icygen.com>
Sent: Tuesday, September 25, 2001 5:13 PM
Subject: Re: [PHP] public and private parts in classes ?
> On Tue, 25 Sep 2001, Andrey Hristov wrote:
>
> > You by yourself showed that you code return:
> > echo "foo: " . $n->foo;
> > // returns 'foo: '
> > but if the code was correct it must return :
> > "foo: bar", not "foo: "
>
> Exactly. Thus, it means that by adding the underscore, I had made the
> property private which was the whole point of the exercise. If the
> property had not been private, then yes the script would have had the
> output "foo: bar". See?
>
> Cheers,
>
> Nick W..
> -[ pioneer@dac.org ]-
>
> :: today's word is..
>
> haggis (n): a small, hairy creature that has 8 long legs, looks like a set
> of bagpipes and tastes good with deep-fried chipped potatoes
>
>
>