最新更新请留意个人github: https://github.com/pfdtk/zephir-docs/tree/master/zh_cnphp
Zephir 是一个开源的,能够用高级语言安全快速地编写 PHP 的 C 扩展。git
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