nodirtyrockstar Posted November 30, 2013 Share Posted November 30, 2013 Is it considered incorrect practice to declare privacy modifiers on variable/properties of subclasses? for example: class SubClass { var $property = 'notice there is no private, public, or protected keyword here'; } Quote Link to comment https://forums.phpfreaks.com/topic/284401-subclasses-privacy-modifiers/ Share on other sites More sharing options...
nodirtyrockstar Posted November 30, 2013 Author Share Posted November 30, 2013 Okay, I found that using the var keyword automatically declares it as public. Does that mean it is still possible to modify privacy with private or protected here? Quote Link to comment https://forums.phpfreaks.com/topic/284401-subclasses-privacy-modifiers/#findComment-1460753 Share on other sites More sharing options...
nodirtyrockstar Posted November 30, 2013 Author Share Posted November 30, 2013 Answered my own question! Quote Link to comment https://forums.phpfreaks.com/topic/284401-subclasses-privacy-modifiers/#findComment-1460754 Share on other sites More sharing options...
Solution kicken Posted November 30, 2013 Solution Share Posted November 30, 2013 var should not be used, it's a PHP4 convention and has been obsolete since PHP5 was released. It's mapped as an alias to public and still works only for backwards compatibility reasons. New code should use either public, private, or protected to declare the variables, which ever is appropriate for that variable. class Klass { public $aPublicVar; protected $aProtectedVar; private $aPrivateVar; } Quote Link to comment https://forums.phpfreaks.com/topic/284401-subclasses-privacy-modifiers/#findComment-1460764 Share on other sites More sharing options...
nodirtyrockstar Posted December 5, 2013 Author Share Posted December 5, 2013 Of course you are right! I was in the JavaScript zone! Quote Link to comment https://forums.phpfreaks.com/topic/284401-subclasses-privacy-modifiers/#findComment-1461303 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.