[Zephir官方文檔翻譯之一] 歡迎來到Zephir!

最新更新請留意個人github: https://github.com/pfdtk/zephir-docs/tree/master/zh_cnphp


歡迎來到Zephir!

Zephir 是一個開源的,能夠用高級語言安全快速地編寫 PHP 的 C 擴展。git

Zephir特色

Zephir的主要特色有:github

Type system dynamic/static
Memory safety pointers or direct memory management aren't allowed
Compilation model ahead of time
Memory model task-local garbage collection

牛刀小試

下面的類中的函數alpha過濾一段字符串,並返回字母字符:安全

namespace MyLibrary;/** * Filter */class Filter{
    /**     * 過濾一段字符串,並返回字母字符     *     * @param string str     */
    public function alpha(string str)
    {
        char ch; string filtered = "";

        for ch in str {
           if (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') {
              let filtered .= ch;
           }
        }

        return filtered;
    }}

一但上面的代碼編譯成擴展後,在php中能夠這樣使用:函數

<?php$filter = new MyLibrary\Filter();echo $filter->alpha("01he#l.lo?/1"); // 輸出 hello
相關文章
相關標籤/搜索