root 发表于 2018-12-17 08:32:12

php7 扩展类的写法[2]

/**  
* 声明构造函数
  
* @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;}


页: [1]
查看完整版本: php7 扩展类的写法[2]