maccy93 Posted December 12, 2011 Share Posted December 12, 2011 I'm learning MVC and getting a bit confused with the accessibility of variables in classes... class Load { public $load2; } Does this mean that the variable $load2 will be accessible just by all functions within the class Load? or: Does that mean that the variable $load2 will be accessible by all other classes, eg model, controller...etc inc all the functions within? Quote Link to comment https://forums.phpfreaks.com/topic/253010-public-load2/ Share on other sites More sharing options...
bluejay002 Posted December 12, 2011 Share Posted December 12, 2011 Generally, "public" is a visibility keyword that tells a variable/method is accessible not just within the class nor by its subclasses, but can also be referenced outside the class, once an object of the class has been instantiated. If some other class is going to use it, it could possibly because the class is a subclass of that parent class that has the public variable, an object of that class was instantiated within the class using it, or the object referencing to that class was passed as a parameter in a method of the class using it. Quote Link to comment https://forums.phpfreaks.com/topic/253010-public-load2/#findComment-1297159 Share on other sites More sharing options...
SergeiSS Posted December 12, 2011 Share Posted December 12, 2011 Do you ever heard about helps? Go to php.net/manual/en, here you'll find a lot of information. For example, read about visibility of class's variables: http://www.php.net/manual/en/language.oop5.visibility.php Here you can find descriptions of public, protected and private properties. Quote Link to comment https://forums.phpfreaks.com/topic/253010-public-load2/#findComment-1297160 Share on other sites More sharing options...
maccy93 Posted December 12, 2011 Author Share Posted December 12, 2011 Ah thanks a lot. That's just what I needed :-) It's always easier when you know what to look for Quote Link to comment https://forums.phpfreaks.com/topic/253010-public-load2/#findComment-1297170 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.