Ben Stones schreef:
Hi, Just started with object oriented programming and glad I have come across it, just need a few things clearing up. When I make a variable or method public, does this mean that it can be used outside of classes, for instance in other classes or as well as instantiating classes? So if I made it private, it wouldn't be able to be instantiated or extended in other classes, am I right? I have never added public when I am creating methods so I presume its already set as default if you don't add it? Hope you can understand my question.
yes, and the answer nearly always lies in trying it out, run this (and if/when you hit a fatal error, comment the offending line and run it again): <?php class Test { public $a = "A"; protected $b = "B"; private $c = "C"; function tryme() { echo $this->a, "\n"; echo $this->b, "\n"; echo $this->c, "\n"; echo $this->d, "\n"; } } class TestTwo { function tryme() { echo $this->a, "\n"; echo $this->b, "\n"; echo $this->c, "\n"; echo $this->d, "\n"; } } $t1 = new Test; $t2 = new TestTwo; $t1->tryme(); echo $t1->a, "\n"; echo $t1->b, "\n"; echo $t1->c, "\n"; echo $t1->d, "\n"; $t2->tryme(); echo $t2->a, "\n"; echo $t2->b, "\n"; echo $t2->c, "\n"; echo $t2->d, "\n"; ?>
Cheers.
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php