Home > Backend Development > PHP Tutorial > Access Modifier Example Tutorial

Access Modifier Example Tutorial

零下一度
Release: 2023-03-14 13:04:01
Original
1203 people have browsed it

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()
{
}
}
Copy after 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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template