Robert,

On Mon, Feb 23, 2015 at 3:27 AM, Robert Stoll <p...@tutteli.ch> wrote:
> Hey all,
>
> tl;dr
>
> Just one point which JIT/AOT people should consider when dealing with PHP. 
> PHP is highly dynamic and there are enough use cases which makes it 
> impossible for a static analyser to infer types accurately without using a 
> top type like mixed.
> How would you deal with variable function calls, variable variables, 
> reflection, dynamic includes etc.
>
> Your inferred types would simply be wrong without using mixed. Consider the 
> following
>
> function foo(int $a){}
> $a = 1;  //can be int for sure right?
> $b = "a";
> $$b = "h"; //oh no, your generated code would crash
> foo($a);
>
> Maybe I am wrong and there is a possibility, if so, please let me know, would 
> be interesting to know.

This very specific example is easy to type. The reason is that we can
use constant propagation to know that $$b is really $a at compile
time. Hence we can reduce it to:

$a = "h";
foo($a);

And hence know **at compile time** that's an error.

This isn't the general case, but we can error in that case (from a
static analysis perspective at least) and say "this code is too
dynamic". In strict mode at least.

Anthony

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to