PHP - 扩展 vs. 库 vs. 类 - 何时以及为什么 [英] PHP - Extension vs. Library vs. Class - when and why

查看:22
本文介绍了PHP - 扩展 vs. 库 vs. 类 - 何时以及为什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试完成一项任务,结果发现我需要的代码被打包为 PHP 扩展,根据我被告知的内容,这意味着我必须拥有 root 访问权限安装它(我在共享主机上,所以这有点问题.

I'm trying to accomplish a task and turns out that the code I need is packaged as a PHP extension, which according to what I've been told means I have to have root access to install it (I'm on shared hosting so that's a bit of a problem.

我稍后会解决这个问题,但现在我试图理解扩展、库和类之间的区别.它更像是一种打包的东西,可以以不同的方式覆盖和重新打包,还是背后有有效的架构推理?

I'll solve this problem later, but for now I'm trying to understand the difference between an extension, a library, and a class. Is it more of a packaging thing that could be overridden and repackaged a different way, or is there a valid architectural reasoning behind it?

此外,在发布您自己的代码时,是什么让您决定以库、类和扩展的形式发布?还是你选择听起来更好的那个?

Also when releasing your own code, what makes you decide to release as library vs. class vs. extension? or do you go with whichever sounds better?

提前致谢.

附言如果你一定要知道我说的是哪个扩展,它是 Libpuzzle,但这确实是除此之外,我的问题更笼统.

P.S. If you must know which extension I'm talking about, it's Libpuzzle, but that's really beside the point, my question is more general.

推荐答案

扩展是低级的.通常用 C/C++ 编写,并编译成本机代码共享库,它们直接与 Zend 引擎交互.它有利有弊,主要优点是速度快,控制力强;和主要缺点 - 它们更难安装,并且需要编译(这需要编译器和 PHP 头文件);但这不是真的,他们需要 root 访问权限 - 您只需要能够使用自定义 php.ini(或 dl() 函数,但我看到他们出于某种原因弃用了它).

Extensions are low-level. Usually written in C/C++, and compiled into native-code shared libraries, they interact with the Zend Engine directly. It has pros and cons, main advantages being the speed and more control; and main disadvantages - they are harder to install, and require compilation (and that requires a compiler and PHP headers); it's not true they require root access though - you only need ability to use custom php.ini (or dl() function, but I see they deprecated it for some reason).

库/类是高级别的和解释性的.如果您不知道是否需要编写扩展程序,那么您可能不需要.关于什么是类 - 阅读OOP.库是可重用的代码集合(最常见的是函数/类的形式).

Libraries/classes are high-level and interpreted. If you don't know if you need to write extension, then you probably don't. About what classes are - read about OOP. A library is a reusable collection of code (most commonly in form of functions/classes).

这篇关于PHP - 扩展 vs. 库 vs. 类 - 何时以及为什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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