PHP 总体上还是程序化的吗?

发布于 2024-09-04 03:15:09 字数 114 浏览 2 评论 0原文

我知道 PHP 5 有一些面向对象的相似之处,但它仍然不是真正的 OOP 环境,对吗?它还有真正的编译器吗?我看到脚本的编译仍然意味着程序化。我认为它不是一个真正的编译器,因为任何 PHP 编译器都不会创建程序集?

I know PHP 5 has some object oriented similarities but it's not a true OOP environment still right? Also does it have a true compiler? I see compiling of scripts which still means procedural. I assume it's not a real compiler in that any PHP compilers out there do not create assemblies?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

遗忘曾经 2024-09-11 03:15:09

我认为你应该阅读一下你所使用的单词的定义!

“程序集”是 .NET 使用的一个词,可以粗略地翻译为“一个 DLL 加上一些可以部署的支持内容”。也许您正在考虑“汇编代码”?

编译器编译为各种表示形式。 JVM 字节码、CLR 字节码、x86 字节码、Python 字节码、MIPS 字节码、ARM 字节码……这些都是编译器的有效目标。请注意,对于 JVM 和 x86 字节码来说,都存在硬件(CPU)和软件(解释器)执行环境,因此目标代码是否是“硬件”并不真正起作用。

当涉及到面向对象、过程性和功能性时,代码编译与代码解释没有任何意义。 OO 与支持多态性、数据隐藏、数据与接口实现和可组合性有关。

PHP 支持所有这些东西,因此您可以使用它以简单的方式实现 OO 设计,所以我会说 PHP 支持 OO。

最后:你应该看看 Facebook PHP 编译器,它将 PHP 编译为 C,然后将 C 编译为 x86,这显然比传统 PHP 执行环境提高了 50% 的速度。

I think you should read up a bit on the definition of the words you're using!

"Assemblies" are a word that .NET uses for something that's loosely translated as "a DLL plus some support stuff that you can deploy." Perhaps you were thinking about "assembly code"?

Compilers compile to all kinds of representations. JVM bytecodes, CLR bytecodes, x86 bytecode, Python bytecode, MIPS bytecode, ARM bytecode, ... Those are all valid targets for a compiler. Note that, for both JVM and x86 bytecode, there exists both hardware (CPU) and software (interpreter) execution environments, so whether the target code is "hardware" or not doesn't really play into it.

Compiling of code versus interpreting of code doesn't mean anything when it comes to OO vs procedural vs functional. OO has to do with supporting polymorphism, data hiding, data-goes-with-interface-implementations and composability.

PHP supports all those things, so you can use it to implement an OO design in a straightforward way, so I would say that PHP supports OO.

Finally: you should look at the Facebook PHP compiler, which compiles PHP to C and then C to x86, which apparently gives it a 50% speed-up compared to the traditional PHP execution environment.

〃温暖了心ぐ 2024-09-11 03:15:09

PHP 现在是一种完全面向对象的语言,即使大多数 API 不是。

  • 它支持类和对象。
  • 它遵循OOP(继承、封装、抽象、多态)的原则,

因此是一种完全面向对象的语言。


PHP 实际上会将其脚本编译(默认情况下每次运行时除非使用“加速器”)为中间字节码,然后由 Zend 引擎运行。

它实际上与其他语言非常接近:

  • VB.NET / C# / F# / 其他 .NET 语言
    这些语言在编译时不会输出汇编代码中的二进制文件,而是输出通用中间语言 (CIL) 中的二进制文件。然后,.NET 虚拟机在运行时解释 CIL 字节码。

  • Java
    Java 编译 .class.jar 文件,这些文件不是汇编代码,而是 Java 字节码。 Java 字节码然后在运行时由 Java 虚拟机解释

  • PHP
    PHP 编译为 Zend 字节码,然后由 Zend 引擎在运行时解释。

PHP is now a completely object oriented language, even if most of the API isn't.

  • It supports class and objects.
  • It follows the principles of OOP (Inheritance, Encapsulation, Abstraction, Polymorphism)

It is therefore a completely object oriented language.


PHP actually does compile (by default on every run unless using "an accelerator") its scripts into intermediary byte-code which is then run by the Zend Engine.

It's actually pretty close to other languages:

  • VB.NET / C# / F# / other .NET Languages
    Those languages when compiled does not output binaries in assembly code, but rather binaries in Common Intermediate Language (CIL). CIL bytecode is then interpreted at runtime by the .NET Virtual Machine.

  • Java
    Java compiles .class and .jar files which are not in assembly code, but rather in Java Bytecode. Java Bytecode is then interpreted at runtime by the Java Virtual Machine

  • PHP
    PHP compiles into Zend Bytecode, which is then interpreted at runtime by the Zend Engine.

§对你不离不弃 2024-09-11 03:15:09

类似的问题讨论过很多次。没有“真”或“假”OOP。由于php支持封装、多态、继承——它是面向对象的编程语言。并且不存在仍然“真正的”编译器。但你可以看看 Facebook 的 Hip-Hop

Similar questions discussed a lot of times. There is no "true" or "false" OOP. Due to php supports encapsulation, polymorphism, inheritance - it is Object Oriented Programming Language. And there are no still "true" compilers. But you can look at Facebook's Hip-Hop

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文