This is an old revision of the document!
This page contains bits and pieces of the Zend Engine documentation:
Op-array structure
- each op_array has an array of literals (constant values)
- opocde operands don't contain zval directly any more but points to thistable instead
- during compilation they are accessible by index e.g:
op_array->literals[opline->op1.constant].constant
- the pass_two() changes indexes into pointers so during execution they are accessible by:
opline->op1.zv
FAQ
These are questions, often times with answers, for the PHP Internals. This document is temporary until it's polished and finds a home within the PHP Manual sources. Feel free to add questions with or without answers.
Note: This is rough, feel free to clean it up.
C++
Extensions can be written in C++, you have to add PHP_REQUIRE_CXX to the config.m4 file to make the build system C++-aware though.
To allow static builds of the extension one has to mind this:
09:20:43 <johannes_> and ext/extname/php_extname.h has to be a valid C header, not C++, as it's included in internal_functions.c ... 09:22:06 <dsp_> hmm, that's the point.. 09:23:01 <johannes_> you can have your own additional header for C++ suff, but that one has to be C compatible
Memory Management
[12:00pm] scoates: ok.. last question for now, I think: should I explicitly destroy on RSHUTDOWN, or let the non-persistent flag take care of that? [12:00pm] johannes_: always cleanup yourself
Note here: while MM shutdown will take care of all allocated memory, it won't run any dtors etc., that's why it is important to clean up the resources properly - otherwise external dependencies can be messed up. And of course you'd get leaks reported in the debug mode.
Causes for crashes
Throwing Exceptions
If throwing exceptions results in a segmentation fault on 64bit systems only, then be sure that you have:
#include "zend_exceptions.h"
(Remark: This header is always needed. The segfault might be caused by the fact, that C defaults the return value and parameters of undefined parameters to int. In cases where pointers and/or long data types are needed this might be wrong so a wrong function call is being made. A good compiler should give a warning. --johannes)
Hashes
[11:58am] scoates: what's the difference between zend_hash_[add] and zend_hash_quick_[add] ? [11:58am] scoates: removal of gofaster loops? (-: [11:58am] Derick: with the 2nd one you can provide an already calculated hash-list index
[11:59am] scoates: and the hashtable will automatically grow on _add, right? the length passed to init is just a hint? [11:59am] johannes_: right
Unsorted
Add your random stuff here. I'll move it/update it/fix it (Derick)