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?
thanks in advance.
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.
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).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).