zephir--The simplest PHP extension development tool

Source: Internet
Author: User

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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.