开发者

Unusual type casting in PHP

开发者 https://www.devze.com 2023-03-27 01:31 出处:网络
We are trying to create an object which methods can be autocompleted by eclipse PDT or Zend Studio but we stuck in a point and I wanted to ask it to you.

We are trying to create an object which methods can be autocompleted by eclipse PDT or Zend Studio but we stuck in a point and I wanted to ask it to you.

The problem is; Eclipse cannot reach the method of a class with the codes below;

class Soup {
    private static $_obj;

    public function __construct(){}

    public static function getObj($objName){
        if(isset(self::$_obj)) {
            return self::$_obj;
        } else {
            self::$_obj = new $objName;
            return self::$_obj;
        }
    }
}

class Foo extends Obj {

}

class Obj {     
    public fun开发者_开发百科ction test() {}
}
// This is what we are trying to reach;
Soup::getObj('Foo')->test();

In PHP there is no problem with this, but in Eclipse PDT or Zend Studio, auto complete does not complete ->test() part. Is there a solution to this on behalf of Eclipse PDT or is there another way to create that class?


All (most) IDEs use docblocks for the more advanced auto-complete features, it's the same with Zend Studio and Eclipse. A good docblock will not only make your code well documented and phpdoc-able but will also give you a lot better code assist!


you can't, and it's not a IDE problem.

in php (unlike java) you dont know the return type of a function. so for php is impossible to know what will Soup:getObj('Foo') return... maybe an object, maybe an array or maybe it wont return anything

In Netbeans you could help him by adding a documentation in the function to tell him that the function returns a Foo object

Hope this Helps

0

精彩评论

暂无评论...
验证码 换一张
取 消