为什么动态构造对于php编译器(HPHP)很难? [英] Why are dynamic constructs difficult for php compilers (HPHP)?

查看:204
本文介绍了为什么动态构造对于php编译器(HPHP)很难?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读Paul Bigger的 http://blog.paulbiggar.com/archive/a-rant-about-php-compilers-in-general-and-hiphop-in-particular/ ,他提到HPHP没有不完全支持动态构造。他然后说,但是,一个天真的方法是只是坚持switch语句,并编译一切有意义的。他是说,而不是动态包括,你可以使用switch语句包括正确的文件?如果是这样,为什么会这样工作,为什么编译器更容易编译?一如往常,thx为你的时间!

I was reading up on Paul Bigger's http://blog.paulbiggar.com/archive/a-rant-about-php-compilers-in-general-and-hiphop-in-particular/ and he mentions that HPHP doesn't fully support dynamic constructs. He then states, "Still, a naive approach is to just stick a switch statement in, and compile everything that makes sense." Is he saying that instead of a dynamic include, you could use switch statements to include the proper file? If so, why would this work and why is it "easier" for a compiler to compile? As always, thx for your time!

推荐答案

编译器期望能够识别所有的源和二进制文件,可能正在编译的程序使用。

A compiler expects to be able to identify all of the source and binary files that might be used by the program being compiled.

include($random_file); 

如果$ random_file中命名的文件声明了常量,类和变量,编译器将无法知道因为$ random_file的值在编译时是未知的。使用这些常量,类和变量的代码将难以调试。 switch语句将知道可能的文件的列表,以便编译器可以发现任何相关的声明。

If the file named in $random_file declares constants, classes, variables, the compiler will have no way knowing because the value of $random_file is not known at compile time. Your code using those constants, classes and variables will fail in difficult-to-debug ways. The switch statement would make known the list of possible files so the compiler can discover any relevant declarations.

设计编译的语言具有动态链接器和外部函数接口,它们组合起来提供类似的功能,以包含($ random_file)而不需要显式切换。

Languages designed to be compiled have dynamic linkers and foreign function interfaces that combine to provide similar functionality to include($random_file) without needing the explicit switch.

这篇关于为什么动态构造对于php编译器(HPHP)很难?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆