Re: Class and subclass

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux