blueman378 Posted May 31, 2008 Share Posted May 31, 2008 hi guys, can someone please explain to me how the public and private keyword works for functions and classes in php 5? Link to comment https://forums.phpfreaks.com/topic/108107-php-5-private-public-what-the/ Share on other sites More sharing options...
Barand Posted May 31, 2008 Share Posted May 31, 2008 http://www.php.net/manual/en/language.oop5.visibility.php Link to comment https://forums.phpfreaks.com/topic/108107-php-5-private-public-what-the/#findComment-554106 Share on other sites More sharing options...
LemonInflux Posted May 31, 2008 Share Posted May 31, 2008 In a nutshell, you have various keywords in PHP5 OOP. private, public, abstract, protected etc. etc. private means it can only be accessed by members of that class public means it can be accessed by the class, parents/children of the class, or completely separate code (in other words, any code anywhere) abstract means it can only be accessed by inherited classes protected means it can only be accessed by children and parents of the class For example: <?php class a { private $_variable = 'hi'; public $var = 'hello'; private function test() { echo 'showing private var $_variable:'. $this->_variable; } public function testing() { echo 'showing test through public function testing()...'; $this->test(); } } a::testing(); // Works a::test(); // Doesn't work $a = new a; echo $a->_variable; // Doesn't work echo $a->var; // Works ?> Excuse errors, I'll try to spot them asap Link to comment https://forums.phpfreaks.com/topic/108107-php-5-private-public-what-the/#findComment-554115 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.