Download the PHP package symplely/zend-ffi without Composer
On this page you can find all versions of the php package symplely/zend-ffi. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download symplely/zend-ffi
More information about symplely/zend-ffi
Files in symplely/zend-ffi
Package zend-ffi
Short Description Provides the base API for creating extensions, or modifying Zend/PHP internal core with FFI.
License MIT
Homepage https://github.com/symplely/zend-ffi
Informations about the package zend-ffi
zend-ffi
Provides the base API for creating extensions, or modifying Zend/PHP internal core with FFI.
- For PHP 7.4, 8.0, 8.1, 8.2, Windows, Mac, Linux
It allows loading of shared libraries (.dll or .so), calling of C functions and accessing of C type data structures in pure PHP.
This package breaks down the Zend extension API into PHP classes getting direct access to all PHP internal actions. You can actually change PHP default behaviors. You will be able to get the behavior of componere extension without needing it.
Many routines here is a rewrite of Z-Engine library package that use different terminology and setup structure. This package follow/keep PHP C source code style with a skeleton FFi installation process.
There are many extensions on Pecl that hasn't been updated.
Installation
For normal standalone usage.
To setup a skeleton for FFI integration.
Minimum php.ini setting:
For a simple FFI integration process create/edit:
ffi_extension.jsoneach package/library should list the files to preload, will be process byffi_preloader.phpscript..ignore_autoload.phpwill be called/executed bycomposer create-project your_package .cdef/foldernameevent.- This event is only called when your package is installed by
composer create-projectcommand.
- This event is only called when your package is installed by
.preload.phpfor general common FFI functions to be used, change thetag_changeMeskeleton name..github\workflows\*.ymlthese GitHub Actions is designed for cross-compiling and committing thebinaryback to your repo, changesome_libandsome_reposkeleton names.- The idea of this is to make installation totally self-contained, the necessary third party library binary is bundled in.
- The CI build Actions is setup for manually runs only.
Documentation
The functions in preload.php and Functions.php should be used or expanded upon.
See tests folder for examples. Copy/paste the code between --FILE-- and --EXPECT-- blocks in the .phpt files.
For general FFI C data handling see CStruct class.
Functions c_int_type(), c_struct_type(), c_array_type() and c_typedef() are wrappers for any C data typedef turning it into PHP CStruct class instance, with all FFI functions as methods with additional features.
For AST handling:
zend_parse_string()will convert PHP source code into native C datazend_astnode held in ZendAst class, useprint_ast()to display results.zend_ast_process(function(\ZE\AstProcess $hook){})to intercept and modify AST after compilation process.
Get the behavior of PHP extensions like nikic/php-ast and sgolemon/astkit that provide low-level bindings to the underlying AST structures, without any addition library.
The whole PHP lifecycle process can be achieved by just extending StandardModule abstract class.
A hack for headers_sent() like errors:
PHP Warning: Cannot modify header information - headers already sent by (output started at xxxxxxxx
To create proper FFI C library headers from any C ABI library *.h file
Linux:
cpp -P -D"__attribute__(ARGS)=" path/to/original/header.h -o ffi_header.h
Windows:
First download mcpp
mcpp -P -D"__attribute__(ARGS)=" path/to/original/header.h -o ffi_header.h
The option -I <directory> might be needed to search/find additional include sources, and the output file will still need editing, mostly 96% proper headers, FFI will complain, just edit/check the 2 lines after the indicated line.
Reference/Credits
- Introduction to PHP FFI
- How to Use PHP FFI in Programming
- PHP FFI and what it can do for you
-
Getting Started with PHP-FFI Youtube
- Zend API - Hacking the Core of PHP
- PHP at the Core A Hacker's Guide - Manual
- PHP Internals Book
- Upgrading PHP extensions from PHP5 to NG
- Extending and Embedding PHP
- Whitepaper: Writing PHP Extensions - Zend PDF
- Part V: Extensibility
- In-depth study of PHP & Zend Engine TSRM Algorithms
- Awesome PHP FFI
- Z-Engine library
Possible Security Risks
The Beginning
Contributing
Contributions are encouraged and welcome; I am always happy to get feedback or pull requests on Github :) Create Github Issues for bugs and new features and comment on the ones you are interested in.
License
The MIT License (MIT). Please see License File for more information.
All versions of zend-ffi with dependencies
ext-ffi Version *