PHPackages                             pixelfederation/z-engine - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. pixelfederation/z-engine

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

pixelfederation/z-engine
========================

Library that provides direct access to native PHP structures

8.3.0(1y ago)25.4k1MITPHPPHP &gt;=8.2

Since Sep 25Pushed 1y agoCompare

[ Source](https://github.com/pixelfederation/z-engine)[ Packagist](https://packagist.org/packages/pixelfederation/z-engine)[ RSS](/packages/pixelfederation-z-engine/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (25)Used By (0)

!!! IMPORTANT !!! - THIS IS JUST A FORK OF THE UNMAINTAINED ORIGINAL PACKAGE FOR SPECIAL CASE USAGE WITH THE SWOOLE BUNDLE. NOTHING ELSE IS SUPPORTED !!!
---------------------------------------------------------------------------------------------------------------------------------------------------------

[](#-important----this-is-just-a-fork-of-the-unmaintained-original-package-for-special-case-usage-with-the-swoole-bundle-nothing-else-is-supported-)

Z-Engine library
----------------

[](#z-engine-library)

[![Build Status](https://camo.githubusercontent.com/55abe5d2ba40026743a9b85edaef80299fd02826dc09ad113f4935d97b48c070/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f6d2f6c6973616368656e6b6f2f7a2d656e67696e652f6d6173746572)](https://travis-ci.org/lisachenko/z-engine)[![GitHub release](https://camo.githubusercontent.com/923019e78b236114dec319ab72520c27a14ea9af00c3e48d5fbd4a82911d651c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6c6973616368656e6b6f2f7a2d656e67696e652e737667)](https://github.com/lisachenko/z-engine/releases/latest)[![Minimum PHP Version](https://camo.githubusercontent.com/92fabb75236db7d7453db0680cfab230e4ba78cc321ad3864794f78327f3f3b0/687474703a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230372e342d3838393242462e737667)](https://php.net/)[![License](https://camo.githubusercontent.com/1984901eb37c10a5a1a3a8a09a0231df9178e0f4d1efc6cbb5cf79671ed608ad/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c6973616368656e6b6f2f7a2d656e67696e652e737667)](https://packagist.org/packages/lisachenko/z-engine)

Have you ever dreamed about mocking a final class or redefining final method? Or maybe have an ability to work with existing classes in runtime? `Z-Engine` is a PHP7.4 library that provides an API to PHP. Forget about all existing limitations and use this library to transform your existing code in runtime by declaring new methods, adding new interfaces to the classes and even installing your own system hooks, like opcode compilation, object initalization and much more.

**⚠️ DO NOT USE IT IN PRODUCTION UNTIL 1.0.0!**

How it works?
-------------

[](#how-it-works)

As you know, PHP version 7.4 contains a new feature, called [FFI](https://www.php.net/manual/en/book.ffi.php). It allows the loading of shared libraries (.dll or .so), calling of C functions and accessing of C data structures in pure PHP, without having to have deep knowledge of the Zend extension API, and without having to learn a third "intermediate" language.

`Z-Engine` uses FFI to access internal structures of... PHP itself. This idea was so crazy to try, but it works! `Z-Engine` loads definition of native PHP structures, like `zend_class_entry`, `zval`, etc and manipulates them in runtime. Of course, it is dangerous, since `FFI` allows to work with structures on a very low level. Thus, you should expect segmentation faults, memory leaks and other bad things.

Pre-requisites and initialization
---------------------------------

[](#pre-requisites-and-initialization)

As this library depends on `FFI`, it requires PHP&gt;=7.4 and `FFI` extension to be enabled. It should work in CLI mode without any troubles, whereas for web mode `preload` mode should be activated. Also, current version is limited to x64 non-thread-safe versions of PHP.

To install this library, simply add it via `composer`:

```
composer require lisachenko/z-engine
```

To activate a `preload` mode, please add `Core::preload()` call into your script, specified by `opcache.preload`. This call will be done during the server preload and will be used by library to bypass unnecessary C headers processing during each request.

Next step is to init library itself with short call to the `Core::init()`:

```
use ZEngine\Core;

include __DIR__.'/vendor/autoload.php';

Core::init();
```

Now you can test it with following example:

```
