您当前的位置:首页 > 网站建设笔记 >

discuzX3.3 discuz_base.php文件代码注释

0
<?php

if (!defined('IN_DISCUZ')) {
  exit('Access Denied');
}

//PHP 5 支持抽象类和抽象方法。定义为抽象的类不能被实例化。
//任何一个类,如果它里面至少有一个方法是被声明为抽象的,那么这个类就必须被声明为抽象的。被定义为抽象的方法只是声明了其调用方式(参数),不能定义其具体的功能实现。

abstract class discuz_base
{
  private $_e;
  private $_m;

  public function __construct() {}

  //试图设置对象未定义的一个属性时调用
  public function __set($name, $value) {
    $setter='set'.$name;

    //bool method_exists(mixed $object, string $method_name)
    //检查类的方法是否存在于指定的object中
    //object 对象示例或者类名
    //method_name 方法名
    //如果method_name所指的方法在object所指的对象类中已定义,则返回true,否则返回false。
    if (method_exists($this,$setter)) {
      return $this->$setter($value);

    //string get_class([object $object=NULL])
    //返回对象实例object所属类的名字
    //object 要测试的对象。如果在类里,此参数可以省略。
    //返回对象实例object所属类的名字。如果object不是一个对象则返回false。
    //如果在一个类里,省略了参数object,则返回当前所在类的名称。
    //如果object是命名空间中某个类的实例,则会返回带上命名空间的类名。
    } elseif ($this->canGetProperty($name)) {
      throw new Exception('The property "'.get_class($this).'->'.$name.'" is readonly');
    } else {
      throw new Exception('The property "'.get_class($this).'->'.$name.'" is not defined');
    }
  }

  //试图获取对象未定义的一个属性时调用
  public function __get($name) {
    $getter='get'.$name;
    if (method_exists($this,$getter)) {
      return $this->$getter();
    } else {
      throw new Exception('The property "'.get_class($this).'->'.$name.'" is not defined');
    }
  }

  //调用未定义方法时调用。它取两个参数:所用的方法名以及一个数组,其中包含传递给该方法的所有值。
  public function __call($name,$parameters) {
    throw new Exception('Class "'.get_class($this).'" does not have a method named "'.$name.'".');
  }

  public function canGetProperty($name) {
    return method_exists($this,'get'.$name);
  }

  public function canSetProperty($name) {
    return method_exists($this,'set'.$name);
  }

  //需要对象的字符串表示时会调用这个方法
  public function __toString() {
    return get_class($this);
  }

  public function __invoke() {
    return get_class($this);
  }
}
?>

建站咨询

在线咨询真诚为您提供专业解答服务

咨询热线

137 1731 25507×24小时服务热线

微信交流

二维码终于等到你,还好我没放弃
返回顶部