mikesta707 Posted August 19, 2009 Share Posted August 19, 2009 I never quite grasped the concept of private functions vs. public functions. What exactly is the difference. Are private functions only callable inside the class itself? say i had a class class foo{ public function hi(){ $this->bar(); } private function bar(){ echo "can't touch this"; } } $foo = new foo(); //would this not work $foo->bar(); //but this wwould work? $foo->hi(); Is there more than just that? Quote Link to comment https://forums.phpfreaks.com/topic/171016-solved-private-functions/ Share on other sites More sharing options...
KevinM1 Posted August 19, 2009 Share Posted August 19, 2009 I never quite grasped the concept of private functions vs. public functions. What exactly is the difference. Are private functions only callable inside the class itself? say i had a class class foo{ public function hi(){ $this->bar(); } private function bar(){ echo "can't touch this"; } } $foo = new foo(); //would this not work $foo->bar(); //but this wwould work? $foo->hi(); Is there more than just that? That's pretty much it. Private methods have their uses, typically as bookkeeping/initialization methods that shouldn't be used by the client system. Quote Link to comment https://forums.phpfreaks.com/topic/171016-solved-private-functions/#findComment-901957 Share on other sites More sharing options...
mikesta707 Posted August 19, 2009 Author Share Posted August 19, 2009 I see, cool, just wanted to clear that up. thanks for the reply! Quote Link to comment https://forums.phpfreaks.com/topic/171016-solved-private-functions/#findComment-901960 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.