Home  >  Article  >  Backend Development  >  同一个父类,两个子类方法互相调用问题?

同一个父类,两个子类方法互相调用问题?

WBOY
WBOYOriginal
2016-06-20 12:45:351691browse

include 'model.php';include 'user.php';class caiji extends model{ public function hi($name){      echo "$name to you say hi \n";   user::say('jack'); //这里调用非静态的类。   user::hello('kate');//这里可以调用静态的没错 }/***************两个类是分开两个文件,用include包含进来的class user extends model{ public static function hello($name){        echo "$name url ".self::$weburl."\n";	  }	  public function say($name){	echo "$name say hello world~~ \n";  }想请问下:同一个父类,子类之间互相调用对方的方法,非静态类如果使用 类名::方法名  会提示Strict Standards: Non-static method caiji::hi() should not be called statically  这种错误。是不是需要调用先实例化类后 ,才能调用user 类的方法?


回复讨论(解决方案)

是的,非静态方法要先实例化后再调用

是的,非静态方法要先实例化后再调用



我把代码实例化了。还是出错?
Fatal error: Using $this when not in object context in 
Statement:
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
Previous article:PHP 上传图片Next article:在Laravel5.* 中使用 AdminLTE