Re: Class and subclass

From: Date: Tue, 13 Mar 2007 17:25:48 +0000
Subject: Re: Class and subclass
References: 1 2 3 4 5 6 7  Groups: php.general 
Request: Send a blank email to php-general+get-250475@lists.php.net to get a copy of this message
Alain Roger wrote:
In fact the problem is that under Zend Studio editor, when i typed : $this->class_A_property->Class_B_method did not appear as valid. if i typed $this->class_A_property , this was valid because $this refered to Class_A. but if you define a property (private $myobject_B) in class A, and create an instance via $this->myobject_B = new Class_B(); after : $this->myobject_B->Class_B_method was displayed as not correct syntax in Zend :-(
This is due to the flexible nature of PHP. If you think about it you'll see that the editor has absolutely no way to know for sure what type of variable it is, since even if you new up Class_B, you could later assign a literal integer to it. You can help Zend Studio (and yourself!) by properly documenting your code... class Class_A {
    /**
     * My instance of B
     *
     * @var Class_B
     */
    private $myobject_B;
    function __construct() {
        $this->myobject_B = new Class_B();
        //This should work
        $this->myobject_B->Class_B_method();
        //this should fail
        $this->myobject_B->Class_B_method;
    }
    function Class_A() {
        return $this->__construct();
    }
} Zend Studio will parse that comment and it will then know what type of data it contains. This works for function docs too, where you can tell it what the types of the parameters are and that of the return value. -Stut

« previous php.general (#250475) next »