本文介绍了php中超类的$ this-> a-> b-> c-> d调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想在课堂上做些什么

Hello i want to make something on classes

我想做一个超级班,那是我所有班级的延伸

i want to do a super class which one is my all class is extended on it

            ____  database class
           /
chesterx _/______  member class
          \
           \_____  another class   

我想像这样调用数据库类中的方法

i want to call the method that is in the database class like this

$this->database->smtelse();



class Hello extends Chesterx{

  public function ornekFunc(){
     $this->database->getQuery('popularNews');
     $this->member->lastRegistered();
  }

}  

当我将超类扩展到任何类时,我想使用其父类名称调用方法

and i want to call a method with its parent class name when i extend my super class to any class

推荐答案

我不太确定您的最后一句话是什么意思,但这是完全正确的:

I'm not quite sure what you mean by your last sentence but this is perfectly valid:

class Chesterx{
 public $database, $member;
 public function __construct(){
   $this->database = new database; //Whatever you use to create a database
   $this->member = new member;
 }
}

这篇关于php中超类的$ this-> a-> b-> c-> d调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 14:41