Types in dynamically typed languages

Niko Sams niko.sams at gmail.com
Sun Jun 29 11:19:19 UTC 2008


Hi,

How can I find out the type of this variable:
$foo = new A();
My Idea:
When an assignmentExpression-node is encountered the type of the
assigned value is detected
by an ExprVisitor-class that walks the expr-ast and returns the Type.
This is easy for the case
above, also for function calls (that have a return-type). For any
other expression an IntegralType
must be used.

next case; function return-type:
function foo() {
    return new A();
}
Here I could In the TypeBuilder for every return statement set the
return-type of the function. But
there could be several return-statements in one function.

PHPEclipse+ZendStudio do this:
/**
 * @return A
 */
function foo() {}
Finding out that type is pretty easy. But as fallback when no docblock
exists the other way
would make sense.

Same for member variables:
class A {
    /**
     * @var B
     */
    public $i;
    public function __construct()
    {
        $this->i = new B();
    }
}


Niko




More information about the KDevelop-devel mailing list