1. 对象中的属性或者函数是 private 或者是 protect的时候,当实例化这个对象的时候,外部是不能访问到这个属性和函数的。

 <?php
  class TestClass
  {
      //private $name;
      public $name;
      public static $staticName;
      protected function getName()
      {   
          return $this->name;
      }   
  
      protected static function getStaticName()
      //public static function getStaticName()
      {   
          return self::$staticName;
      }   
  
  }
  
  $test = new TestClass();
  //$getName = $test->getName();
  $getStaticName = TestClass::getStaticName();
  var_dump(1111, $getStaticName);exit;
                                                                                                                                                               
  ?>
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
猜你喜欢
  • 2022-12-23
  • 2021-09-17
  • 2021-10-18
  • 2022-12-23
  • 2021-09-23
  • 2021-12-16
  • 2022-12-23
相关资源
相似解决方案