marcbraulio Posted March 12, 2012 Share Posted March 12, 2012 I just have a quick question, what happens if I don't assign a visibility element to methods? In other words, if I just have: class Article_model { public $data; function index() { return $data; } [code=php:0] ...instead of declaring public, private, static, and so on before the function. Will php just consider it public? Quote Link to comment https://forums.phpfreaks.com/topic/258772-assigning-the-visibility-of-methods/ Share on other sites More sharing options...
Psycho Posted March 12, 2012 Share Posted March 12, 2012 http://php.net/manual/en/language.oop5.visibility.php Quote Link to comment https://forums.phpfreaks.com/topic/258772-assigning-the-visibility-of-methods/#findComment-1326566 Share on other sites More sharing options...
marcbraulio Posted March 12, 2012 Author Share Posted March 12, 2012 Ok, so a method without a declared visibility is considered public, so why bother declaring "public"? Good practice? To simply make it more readable? Quote Link to comment https://forums.phpfreaks.com/topic/258772-assigning-the-visibility-of-methods/#findComment-1326570 Share on other sites More sharing options...
trq Posted March 12, 2012 Share Posted March 12, 2012 I think it helps with readability. Quote Link to comment https://forums.phpfreaks.com/topic/258772-assigning-the-visibility-of-methods/#findComment-1326573 Share on other sites More sharing options...
xyph Posted March 12, 2012 Share Posted March 12, 2012 If they ever decided to change default behaviour, a script that doesn't rely on defaults wouldn't be affected. Will this happen? Probably not. Relying on defaults that you have no control over is generally a bad idea. Quote Link to comment https://forums.phpfreaks.com/topic/258772-assigning-the-visibility-of-methods/#findComment-1326597 Share on other sites More sharing options...
marcbraulio Posted March 12, 2012 Author Share Posted March 12, 2012 Understood. Many thanks for all the replies =] Quote Link to comment https://forums.phpfreaks.com/topic/258772-assigning-the-visibility-of-methods/#findComment-1326598 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.