Innovate faster and cut risk with PHP experts from Zend Services.
See How Zend Helps Leading Hosting Providers Keep Their Managed Sites on Secure PHP
Learn PHP from PHP experts with free, on-demand, and instructor led courses.
Submit support requests and browse self-service resources.
To help you learn the basics about PHP, the tutorial we just completed described how to build a very simple practice extension. The following sections provide information that answer common questions and minimize issues relating to:
LINKING EXTERNAL LIBRARIES
Often, PHP extensions are created to provide binding to some third-party C library. In this case, your PHP extension must be linked with this library. This is done through extension configuration file “config.m4” (or “config.w32” on Windows). For example, the following “config,m4” would be used for zstd extension, that implements binding to libzstd:
[for zstd support],
[Include zstd support])])
if test “$PHP_ZSTD” != “no”; then
AC_DEFINE(HAVE_ZSTD, 1, [ Have zstd support ])
PHP_NEW_EXTENSION(zstd, zstd.c, $ext_shared)
When an extension uses an external library, we use --with-<feature> option instead of --enabel-<feature>, and therefore PHP_ARG_ WITH() macro instead of PHP_ARG_ENABLE(). Also, a few special macros were added to find the library and include paths, through pkg-config, and add special rules into the final Makefile.
When you start writing a new extension, try to use a consistent naming convention. There are few alternatives:
PHP has one more type: resource. This type was historically used when you had to keep some C data in PHP zval (e.g. file descriptors). It’s represented as a child of zend_refcounted structure with a pointer to some C data structure.
PHP resources are still used in PHP extensions. However, it’s not recommended to use them for new extensions, because you may implement smarter and more efficient solutions by embedding C data into PHP internal objects.
Request PDF Version