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? 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 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? 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. 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. 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 =] 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
Archived
This topic is now archived and is closed to further replies.