美文网首页
php之三种权限(OOP)

php之三种权限(OOP)

作者: 骚伦 | 来源:发表于2017-09-15 15:15 被阅读0次

public 表示全局,类内部外部子类都可以访问;
private表示私有的,只有本类内部可以使用;
protected表示受保护的,只有本类或子类或父类中可以访问;

//父类
class father{
          public function a(){
               echo "function a";
         }

           private function b(){
                echo "function b";
          }

            protected function c(){
                 echo "function c";
            }
}
//子类
class child extends father{
                  function d(){
                     parent::a();//调用父类的a方法
                 }
                  function e(){
                      parent::c(); //调用父类的c方法
                 }
                  function f(){
                       parent::b(); //调用父类的b方法
                }
}


$father=new father();
$father->a();
$father->b(); //显示错误 外部无法调用私有的方法 Call to protected method father::b()
$father->c(); //显示错误 外部无法调用受保护的方法Call to private method father::c()
$chlid=new child();
$chlid->d();
$chlid->e();
$chlid->f();//显示错误 无法调用父类private的方法 Call to private method father::b()

相关文章

  • php之三种权限(OOP)

    public 表示全局,类内部外部子类都可以访问;private表示私有的,只有本类内部可以使用;protecte...

  • PHP Traits

    (http://php.net/manual/en/language.oop5.traits.php#langua...

  • 魔术方法

    官方文档:http://php.net/manual/zh/language.oop5.magic.php __c...

  • PHP OOP小结

    PHP面向对象 继承 设计一个MySQL数据库操作类 抽象类,抽象方法 接口 interface 类的自动加载

  • OOP PHP 要点

    关于MVC模型:MVC模型有两种模式,一种是所有Model与View层之间的操作都需要通过control 层调度。...

  • PHP OOP编程从入门到不会

    PHP object-oriented programming OOP中的一些基本概念 OOP基本概念代码实例 O...

  • js珠峰高级003

    ###POP : C ###OOP: JAVA PHP C# .net JS Python Ruby Go ###...

  • en

    https://www.php.net/manual/en/language.oop5.overloading.p...

  • 2020-03-16 Spring-Aop

    简介 AOP:面向切面编程,是OOP的扩展和延申,解决OOP中遇到的问题可以进行权限校验,日志记录,性能监控,事务...

  • php的魔术方法 __call

    官方文档 https://www.php.net/manual/en/language.oop5.overload...

网友评论

      本文标题:php之三种权限(OOP)

      本文链接:https://www.haomeiwen.com/subject/lknssxtx.html