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'; } 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? 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! Link to comment https://forums.phpfreaks.com/topic/284401-subclasses-privacy-modifiers/#findComment-1460754 Share on other sites More sharing options...
kicken Posted November 30, 2013 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; } 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! Link to comment https://forums.phpfreaks.com/topic/284401-subclasses-privacy-modifiers/#findComment-1461303 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.