Home  >  Article  >  Backend Development  >  Access Modifier Example Tutorial

Access Modifier Example Tutorial

零下一度
零下一度Original
2017-07-25 12:01:321167browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn