ballhogjoni Posted October 25, 2008 Share Posted October 25, 2008 I have searched google but havent found a great answer. What is the point of typing "public " or "private" in front of a functionname() Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted October 25, 2008 Share Posted October 25, 2008 my understanding of it, is its similar to variable scope in a way, I think Private functions can only be used within the class its declared in, and public functions can be used in the class its defined in, as well as classes that extend it etc... however in saying that, I'm not entirely sure. Quote Link to comment Share on other sites More sharing options...
Guest Posted October 25, 2008 Share Posted October 25, 2008 They do what their english meanings imply: public functions/variables are available outside and inside the class. Private functions/variables are available only inside the class. Protected ones, on the other hand, are available only inside the class, and in the classes that extend it. Example: class Foo { public function foo() { // these will work $this->foo(); $this->bar(); $this->boo(); } protected function boo() { ... } private function bar() { ... } } class Bar extends Foo { public function hello() { $this->foo(); // works $this->boo(); // works $this->bar(); // does not work } } $ex = new Foo(); $ex->foo(); // work $ex->boo(); // does not work $ex->bar(); // does not work Hopefully that makes sense. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.