2016-04-08 00:26
浏览 100

在静态方法中创建当前类的对象 - PHP

I have some problems with my class Model and other classes so I made this simple example to explain my problem :

class person{

  public static $a = "welcome";

  public function __construct(){

  public static function getobject()
      $v = new person();
      return $v;


class student extends person{

  public static $b = "World";


$st = student:getobject();//this will return person object but I want student object

echo $st->$b; // There is an error here because the object is not student

So I want to know what to write instead $v = new person(); to get the object of the last inherited class.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题