When create DUContexts

Niko Sams niko.sams at gmail.com
Sat Jun 14 10:42:00 UTC 2008


>> function foo() {
>>     if (true) {
>>         $i = 1;
>>     }
>>     echo $i; //prints 1
>> }
> I don't exactly know php, but in C++ you would create:
> - A context for foo parameters
> - A context for foo body, which imports parameters
> - A context for the condition in the if statement
> - A context for the compound statement behind the if statement, that imports
> the conditions context
the problem is that $i is defined in line 3 in its own context and
used in an outer context.
In c++ this is not possible, but in php I would have to import the
"if-body" context or something.
OR: do we need a new context for the if-statement at all? (probably a
very naive idea...)

> What bothers me more than creating context when it comes to dynamic languages
> is the creation of Declarations. You will probably have to create a
> Declaration on the first assignment to a name, but will you be able to tell
> that declarations type?
I haven't thought about that much yet :D

that case would be fairly easy:
class A {}
$foo = new A();

but that one is hard:
function createA() { return new A() }
$foo = createA();

the return-type of the createA function has to be evaluated to get the
correct type.
Do you think this might be possible?

This is now impossible without running the code:
$i = 'A';
$foo = new $i();

another idea:
/**
  * @return A
  **/
function createA() { return new A() }
$foo = createA();

niko




More information about the KDevelop-devel mailing list