php7擴充套件開發 5 本類內函式呼叫

2022-08-04 01:42:19 字數 1983 閱讀 7380

2.1在php_person.h中增加:

php_method(person_ce,callback);

php_method(person_ce,setkey);

2.2 實現**

在php_initest.h中開啟全域性變數設定塊的注釋,改成自己相要的變數如下

//新增定義

zend_begin_arg_info_ex(global_setkey_arg, 0, 0, 2)

zend_arg_info(0, setkey1)

zend_arg_info(0, setkey2)

zend_end_arg_info()

const zend_function_entry person_functions = ;

zend_method(person,setkey)

zend_update_property(person_ce, getthis(), "param1", sizeof("param1")-1, param1 tsrmls_cc);

zend_update_property(person_ce, getthis(), "param2", sizeof("param2")-1, param2 tsrmls_cc);

}zend_method(person,callback)

zend_method(person,callback_function)

//釋放資源空間

*return_value=*retval;

zval_copy_ctor(return_value);

zval_ptr_dtor(&retval);

}

type_spec是格式化字串,其常見的含義如下:

引數 代表著的型別

b boolean

l integer 整型

d floating point 浮點型

s string 字串

r resource 資源

a array 陣列

o object instance 物件

o object instance of a specified type 特定型別的物件

z non-specific zval 任意型別~

z zval**型別

f 表示函式、方法名稱

對應的接收變數型別

引數 對應c裡的資料型別

b zend_bool

l long

d double

s char*, int 前者接收指標,後者接收長度

r zval*

a zval*

o zval*

o zval*, zend_class_entry*

z zval*

z zval**

zend_parse_parameters中的 | ,這個表示 在它之前的引數是必須的,之後的是非必須的

2.4 擴充套件使用

[root@bogon tests]# cat test.php

<?php

$n = new person(array('key'=>'value'));

$n->setkey('testparam1','testparam2');

var_dump($n->param1);

var_dump($n->param2);

[root@bogon tests]# php test.php

string(10) "testparam1"

string(10) "testparam2"

array(1)

PHP7擴充套件開發入門

我們可以在ext目錄下看到所有的php原生擴充套件,其中包括了熟悉的curl,json,mbstring,xml,sockets等擴充套件,還有很多沒有用過甚至沒有聽說過的擴充套件,不用在意這些,我們先開啟我們最熟悉的curl來看看,有config.m4配置檔案,有php curl.h,curl f...

PHP7擴充套件開發之hello word

原文出處 本文是以php7作為基礎,講解如何從零開始建立乙個php擴充套件。本文主要講解建立乙個擴充套件的基本步驟都有哪些。示例中,我們將實現如下功能 echo say 輸出內容 php test.php hello word 在擴充套件中實現乙個say方法,呼叫say方法後,輸出 hello wo...

PHP7擴充套件開發之hello word

echo say 輸出內容 php test.php hello word在擴充套件中實現乙個say方法,呼叫say方法後,輸出 hello word。php為我們提供了生成基本 的工具 ext skel。這個工具在php源 的.ext目錄下。cd php src ext ext skel extn...