More technical articles on PHP http://www.codefrom.com/
PHP extension is written in C language, Zend is the language engine, PHP kernel. In the actual writing PHP extension, need to use a lot of Zend Api, although the operation of high efficiency, but in fact, the difficulty is relatively large. See: http://php.net/manual/zh/internals2.ze1.zendapi.php
Zephir provides a high-level language syntax similar to PHP to automatically generate extended C language code, making PHP extensions very easy to write.
Official website: http://www.zephir-lang.com/
Official Installation Tutorial: http://www.zephir-lang.com/welcome.html
Need to install related dependencies under Ubuntu
$ sudo apt-get update$ sudo apt-get install git gcc make re2c php5 php5-json Php5-dev Libpcre3-dev
Of course, other platforms according to the actual prompts, install the corresponding program can be
$ git clone https://github.com/phalcon/zephir$ cd zephir$./install-json$./install-c
Test whether the installation was successful
$ Zephir Help
Examples of use are:
$ Zephir Init utils
is generated under the current directory
Ext/utils/config.json
Then edit the Greeting.zep content under the Utils subdirectory as follows:
namespace Utils; Class Greeting {Public static function say () { var a = ' Hello World '; Echo Strtoupper (a); } }
The namespace here is the one that must be added, with the output uppercase "Hello,world". You can use PHP's built-in functions directly.
And then run
$ Zephir Build
You will then build utils.soin the extended directory and modify the php.ini add to add the extension. Call Method:
Extended read:
Zephir generated by default in the C language file /ext/utils/greeting.zep.c , the core content is as follows:
php_ METHOD (utils_greeting, say) {Zval *a, *_0; Zephir_mm_grow (); Zephir_init_var (a); Zval_string (A, "Hello World", 1); Zephir_init_var (_0); Zephir_fast_strtoupper (_0, a); Zend_print_zval (_0, 0); Zephir_mm_restore ();}
The can be found Zephir directly Zend API such as: Zend_print_zval. On the other hand encapsulates the Zend API, such as: Zephir_fast_strtoupper. Directly modify the file's C code, using the original PHP extension of the editing method can also be dropped.