0

Do i need Zend extensions, or lower level Zend Engine, to create ext.so from ext.c, ext.h and config.m4 ? Is it enough to write ext.h, ext.c and config.m4 files?

old question: Do i need Zend framework to write php extension in c?

This tutorial explains ZEND. https://docstore.mik.ua/orelly/webprog/php/ch14_01.htm

This example does not use ZEND: Compiling a PHP extention library on Ubuntu (Karmic Koala)

Deepak Rai
  • 2,163
  • 3
  • 21
  • 36
Gintare Statkute
  • 677
  • 2
  • 8
  • 18
  • 1
    You don't need zend framework. However PHP runs on the zend engine and any extension you write will probably need to make use of the zend engine API to some extent – apokryfos Feb 04 '21 at 21:46
  • 1
    Other than sharing a name, Zend Framework (a user-land PHP framework that has now been rebranded as [Laminas](https://getlaminas.org/)), has absolutely nothing do with the Zend Engine (or Zend Extensions), which are related to the language itself. – iainn Feb 04 '21 at 21:52
  • Do i need Zend extensions, or lower level Zend Engine, to create ext.so from ext.c, ext.h and config.m4 ? – Gintare Statkute Feb 04 '21 at 22:12
  • Depends what the extension needs to do. Most of the time just using the Zend engine API (e.g. the methods it provides to create/manipulate PHP objects etc) is enough. However if you need to extend the zend engine itself you need zend extensions – apokryfos Feb 04 '21 at 22:59

1 Answers1

3

The question isn't really meaningful; you've misunderstood some terms.

  • The name "Zend" is a portmanteau of "Zeev" and "Andi", the names of two key figures in PHP's history. They used it as the brand for several of their projects.
  • "Zend Framework" is (or was) a PHP application framework, like Symfony, CakePHP, Phalcon, etc. It was recently renamed Laminas. It has nothing to do with extension development, or the core of PHP, it was just founded by Zeev and Andi.
  • "Zend Engine" is the internal compilation and execution system which PHP runs on since PHP 4.0. If you have PHP, you have the Zend Engine, it's not something you have to add separately.
  • PHP provides two different sets of extension hooks: one set is for "PHP extensions" which want to extend the PHP language (provide additional functions, objects, stream wrappers, etc); the other is for "Zend extensions" which want to extend the underlying compilation and runtime system (the Zend Engine). Most extensions you'll use are "PHP extensions"; OpCache and XDebug would be common examples of "Zend extensions".

So, to create a PHP extension, you use the set of APIs - C functions and macros - defined for that purpose, and compile the result against a copy of the PHP source (which includes the Zend Engine). If you are doing something lower-level to the language, you might instead use the set of APIs defined for "Zend extensions", and compile that.

IMSoP
  • 89,526
  • 13
  • 117
  • 169
  • 1
    Thank you so much for clarification. Indeed, i get very confused between many different ways to create PHP extension, and between Zend engine and Zend Framework which are totally different things. I have found very useful examples in PHP dev folders, like php-8.0.2-src/ext/standard/, and most of functions in php-8.0.2-src/Zend/ . My conclusion is that for the compatibility reasons better to have only one function accepting and returning parameters written in Zend Extension, the rest i write in pure C. But, nothing is working yet. – Gintare Statkute Feb 17 '21 at 23:29
  • @GintareStatkute You may have spotted it already, but there's also an ext/skeleton which is just a sample of a very simple extension. Looking at some simple examples from PECL might also be helpful. Good luck! – IMSoP Feb 18 '21 at 08:28