php核心總結 深入PHP核心之物件導向總結

2021-10-22 21:38:26 字數 1760 閱讀 2368

很久以前看過的,今天總結一下

一、php中建立乙個類

在php中建立乙個簡單的類是這樣的:

$obj = new test($url)

二、zend_class_entry結構

zend_class_entry是核心中定義的乙個結構體,是php中類與物件的基礎結構型別。

struct _zend_class_entry zend_arg_info;

接受引數.那麼就要執行

zend_begin_arg_info(test___construct_arginfo, 0)

zend_arg_info(0, url)

zend_end_arg_info()

zend_begin_arg_info_ex定義在zend/zend_api.h

define zend_begin_arg_info_ex(name, pass_rest_by_reference, return_reference, required_num_args)      \

static const zend_arg_info name = ,

zend_arg_info(0,url)的定義如下

#define zend_arg_info(pass_by_ref, name) ,

最終是這樣的

static const zend_arg_info name = ,

,七、定義乙個類

1、申明

static zend_class_entry *test_ce;

2、新增方法

const zend_function_entry test_methods =

//zend_acc_ctor標示建構函式

//zend_acc_dtor標示析構函式

3、php_minit_function中初始化

php_minit_function(test)

/*定義乙個temp class*/

zend_class_entry ce;

/*初始化這個class,第二個引數是class name, 第三個引數是class methods*/

init_class_entry(ce, "test", test_methods);

/*註冊這個class到zend engine*/

test_ce = zend_register_internal_class(&ce tsrmls_cc);

return success;

4、定義引數

zend_begin_arg_info(test___construct_arginfo, 0)

zend_arg_info(0, url)

zend_end_arg_info()

5、具體方法

static php_method(test, __construct) {

char *url;

int url_len;

if (zend_parse_parameters(zend_num_args() tsrmls_cc, "s", &url, &url_len, &age) == failure) {

return;

zval *obj;

obj = getthis();

zend_update_property_stringl(test_ce, obj, "url", sizeof("url") -1, url, url_len tsrmls_cc);

6、在php中訪問

$c = new test('');

深入理解php核心

第二章 使用者 的執行 第三節 zend引擎與指令碼執行 第四節 小結 第三章 變數及資料型別 第二節 常量 第三節 預定義變數 第四節 靜態變數 第五節 型別提示的實現 第六節 變數的生命週期 第七節 資料型別轉換 第八節 小結 第四章 函式的實現 第二節 函式的定義,引數及返回值 第三節 函式的...

深入理解php核心

第二章 使用者 的執行 第三節 zend引擎與指令碼執行 第四節 小結 第三章 變數及資料型別 第二節 常量 第三節 預定義變數 第四節 靜態變數 第五節 型別提示的實現 第六節 變數的生命週期 第七節 資料型別轉換 第八節 小結 第四章 函式的實現 第二節 函式的定義,引數及返回值 第三節 函式的...

深入php核心六(使用擴充套件)

根據你所選擇的不同的構建過程,你要麼把擴充套件編譯進乙個新的php 的二進位制檔案,然後再連線到 web 伺服器 或以cgi 模式執行 要麼將其編譯成乙個 so 共享庫 檔案。如果你將上面的樣例檔案 first module.c 編譯成了乙個共享庫,那麼編譯後的檔案應該是 first module....