Home >Backend Development >PHP Tutorial >Access Modifier Example Tutorial
1. public: The permissions are the largest and can be called internally and instance calls
2. protected: protected type, used for calls of this class and inherited classes
Common scenarios in permissions Setting
<?php namespace apprightcontroller; class Base extendsappcommoncontrollerBase { protected $beforeActionList = [ “checkLogin”, ]; protected function checkLogin() { } //退出登录 public function logout() { } } <?php namespace apprightcontroller; class Login extendsappcommoncontrollerBase { public function login() { } }
has a Class that requires permissions. As long as you inherit the Base class, you can use login verification. When executing Login, the methods in Base will be run first
3. private: Private type, only used in this class.
4. static: Generally used when passing a value, indicating that the value will not be modified. The default is public and can be accessed with::
<?php namespace appcommonmodel; class User extends Base { public static function login($name, $pwd) { } } appcommonmodelUser::login($name, $pwd);
In short, apply good modifiers and do a good job Permissions control access.
The above is the detailed content of Access Modifier Example Tutorial. For more information, please follow other related articles on the PHP Chinese website!