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   //运行ext_skel创建扩展的开发包

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])
  • ****dnl  在这是注释的意思。去掉dnl 就是打开 这一行的意思

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头中加上

/*定义类*/
zend_class_entry *person_ce;
/**
* 声明构造函数
* @param
* @return
*/
ZEND_METHOD(person,__construct){
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"); } /*NULL 表示不传参数
*
*  ZEND_ACC_PUBLIC  说明是public  方法
* ZEND_ACC_CTOR  说明是构造函数
* ZEND_ACC_DTOR 说明是析构函数
*/
const zend_function_entry person_functions[] = { ZEND_ME(person, __construct,NULL, 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[] */
}; //将类和方法注册到zend
PHP_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;
}

执行  命令  phpize

./configure

make

make install  或者 手动cp

改更php.ini 加上[person] extenstion=person.so

使用扩展:

[root@bogon tests]# cat test.php
<?php $n = new person();
echo $n->saying();
echo $n->doing(); [root@localhost tests]# php test.php
construct
saying
doing
destruct

该文章参考与:

原链接:http://www.djhull.com/phpext/php-ext-2.html

  • 请尊重本人劳动成功,可以随意转载但保留以下信息
  • 作者:岁月经年
  • 时间:2016年03月

php扩展开发2--添加类的更多相关文章

  1. php扩展开发3--扩展类传参数

    1.需要实现的细节 实现一个person类 ,实现一个doing方法和saying方法 在构造方法中传递一个数组,在doing中打印此数组 saying方法中,构建一个空数组,返回,不需要传参. 2. ...

  2. 用扩展开发一个PHP类

    原文:http://my.oschina.net/mickelfeng/blog/122519?p=1 假设我们要用PHP扩展实 现一个类Person,它有一个private的成员变量$_name和两 ...

  3. PHP扩展开发(4) - 多类扩展

    由于函数和单类的扩展,网上一搜一大片,这里就不再叙述了. 这里特别感谢laruence(鸟哥)开源的yaf扩展,解决困扰我多时的多类问题,还在看他的代码学习中,这里是对多类写法学习的一个阶段总结.   ...

  4. PHP扩展开发之简单类开发

    接下来我们要用扩展的形式实现以下类(演示环境:linux.php-5.5.34-src) <?php class Person { private $_name; public function ...

  5. PHP扩展开发-简单类扩展

    今天来学习简单类扩展开发 实现目标为如下php的类 <?php class classext(){ private $username; CONST URL="http://www.g ...

  6. iOS开发系列--App扩展开发

    概述 从iOS 8 开始Apple引入了扩展(Extension)用于增强系统应用服务和应用之间的交互.它的出现让自定义键盘.系统分享集成等这些依靠系统服务的开发变成了可能.WWDC 2016上众多更 ...

  7. ios怎样实现快速将显卡中数据读出压缩成视频在cocos2dx扩展开发中

    如果解决ios怎样实现快速将显卡中数据读出压缩成视频在cocos2dx扩展开发中 手机平台性能是个关键问题. 压缩视频分成3个步骤: 读取显卡数据, 使用编码器压缩,保存文件. 使用libav 压缩的 ...

  8. ArcGIS 10.1 for Server 扩展开发(SOE)

    原文连接:http://blog.csdn.net/arcgisserver_book/article/details/7869368 第一章为什么使用SOE 在ArcGIS 10.1中ArcGIS ...

  9. 【干货】Chrome插件(扩展)开发全攻略(不点进来看看你肯定后悔)

    写在前面 我花了将近一个多月的时间断断续续写下这篇博文,并精心写下完整demo,写博客的辛苦大家懂的,所以转载务必保留出处.本文所有涉及到的大部分代码均在这个demo里面:https://github ...

随机推荐

  1. POJ1287 Networking

    解题思路:Kruskal模板题,重复输入的情况,本题是无向图. 见代码: #include<cstdio> #include<algorithm> #include<cs ...

  2. Python [Leetcode 374]Guess Number Higher or Lower

    题目描述: We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have t ...

  3. asp.net core microservices 架构之 分布式自动计算(二)

    一  简介                   上一篇介绍了zookeeper如何进行分布式协调,这次主要讲解quartz使用zookeeper进行分布式计算,因为上一篇只是讲解原理,而这次实际使用, ...

  4. 小而实用的工具插件集锦(JQGrid,zTree)

    jqgrid,JQGrid是一个在jquery基础上做的一个表格控件,看起来感觉还可以,以ajax的方式和服务器端通信 效果图: 这个小东西,多用在在工作流上面. 中文文档: http://blog. ...

  5. 【LIUNX】目录或文件权限,权限授予

    三个三个一组看: 1. 第一段表示文件所有者对此文件的操作权限 2. 第二段表示文件所有者所在组对些文件的操作权限 3. 第三段表示除上述两种外的任何用户/组对此文件的操作权限 r读取:4 w写入:2 ...

  6. 数据立方体----维度与OLAP

    前面的一篇文章——数据仓库的多维数据模型中已经简单介绍过多维模型的定义和结构,以及事实表(Fact Table)和维表(Dimension Table)的概念.多维数据模型作为一种新的逻辑模型赋予了数 ...

  7. #51单片机#超声波测距(HC-SR04)的使用方法

    #51单片机#超声波测距(HC-SR04)的使用方法

  8. hbase官方文档(转)

    FROM:http://www.just4e.com/hbase.html Apache HBase™ 参考指南  HBase 官方文档中文版 Copyright © 2012 Apache Soft ...

  9. Volley的post使用

    直接看代码,注意在manifest中加入Internet权限 <uses-permission android:name="android.permission.INTERNET&qu ...

  10. Indy10收发Hotmail邮件

    hotmail开放了pop3,可以使用客户端工具收取邮件了. POP 服务器: pop3.live.com (端口 995)需要 POP SSL?: 是的用户名: Windows Live ID, 比 ...