PHP中7怎么写扩展类,哪些细节要注意
Admin 2022-08-01 群英技术资讯 1129 次浏览
在实际应用中,我们有时候会遇到“PHP中7怎么写扩展类,哪些细节要注意”这样的问题,我们该怎样来处理呢?下文给大家介绍了解决方法,希望这篇“PHP中7怎么写扩展类,哪些细节要注意”文章能帮助大家解决问题。
1.需要实现的细节
实现一个person类
实现一个doing方法和saying方法
2.第一个扩展
2.1创建类的扩展:
[root@bogon ext]# cd /usr/local/src/php-7.0.3/ext [root@bogon ext]# ./ext_skel --extname=person
2.2 修改配置
[root@bogon ext]# vim person/config.m4 dnl PHPARGWITH(person, for person support, dnl Make sure that the comment is aligned: dnl [ --with-person Include person support])
更改为:
PHPARGWITH(person, for person support, dnl Make sure that the comment is aligned: [ --with-person Include person support])
2.3 实现代码
在php_person.h头中加上
extern zend_class_entry *person_ce; PHP_METHOD(person_ce,__construct); PHP_METHOD(person_ce,saying); PHP_METHOD(person_ce,doing);
在person.c头中加上
/** * 声明构造函数 *
@param * @return */
ZEND_METHOD(person,__construct){
zval *pThis;
pThis = getThis();
zend_printf("construct\n");
}
/** * 声明析造函数 *
@param * @return */
ZEND_METHOD(person,__destruct){
zend_printf("destruct\n");
}
ZEND_METHOD(person,doing){
zend_printf("doing\n");
}
ZEND_METHOD(person,saying){
zend_printf("saying\n");
}
//这个函数需要加上声明,去掉了没用的test函数const zend_function_entry person_functions[] = {
ZEND_ME(person, __construct, global_config_arg, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
ZEND_ME(person,doing,NULL,ZEND_ACC_PUBLIC) ZEND_ME(person,saying,NULL,ZEND_ACC_PUBLIC)
ZEND_ME(person,__destruct,NULL,ZEND_ACC_PUBLIC|ZEND_ACC_DTOR)
PHP_FE_END
/* Must be the last line in person_functions[] */
};
//将类和方法注册到zendPHP_MINIT_FUNCTION(person){
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "person", person_functions);
person_ce = zend_register_internal_class(&ce TSRMLS_CC);
zend_declare_property_null(person_ce,"saying",strlen("saying"),ZEND_ACC_PUBLIC);
zend_declare_property_null(person_ce,"doing",strlen("doing"),ZEND_ACC_PUBLIC);
return SUCCESS;
}2.4 编译
* [root@bogon hello]# [root@localhost person]# ./configure && make && make install
2.5 扩展安装
改更php.ini 加上
[person] extenstion=person.so
2.6 扩展使用
[root@bogon tests]# cat test.php <?php $n = new person(); echo $n->saying(); echo $n->doing(); [root@localhost tests]# php test.phpconstructsayingdoingdestruct
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
在“Laravel5.4”中,软删除指的是将表记录的状态标记上删除状态,并不是真正的从数据库中删除了,这样在查询的时候就可以添加过滤;软删除能够在表中以“deleted_at”字段值进行标识,默认值为null。
Session中文译名叫做“会话”,其本来的含义是指有始有终的一系列动作/信息。PHP session变量用于存储关于用户会话(session)的信息,或者更改用户会话(session)的设置。Session变量存储单一用户的信息,并且对于应用程序中的所有页面都是可用的。
在学习PHP时,我们比较常见的PHP设计模式有策略模式。工厂模式、单例模式、注册模式和适配器模式这五种,当然PHP设计模式还有很多。这篇文章主要给大家介绍的是关于适配器模式的原理以及用法等等,感兴趣的朋友接着看。
thinkphp默认使用的是内置模板引擎,是一个自主创新的XML编译性模板引擎;内置模板引擎支持模板文件中采用php原生态代码和模板标签的混合使用,视图的模板文件可以支持不同的解析规则,默认情况下无需手动初始化模板引擎。
1、使用header()设置过期时间。2、使用header()设置页面的最后更新日期为当天,可以强制浏览器获取最新资料。3、使用header()告诉客户端浏览器不使用缓存。
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008