78 物件屬性讀寫

2021-07-11 11:30:28 字數 3159 閱讀 5840

這一節主要描述與物件屬性有關的東西。有關如何對它進行定義的操作我們已經在上一章中描述過了,這裡不再敘述,只講對其的操作。

zend_api zval *zend_read_property(zend_class_entry *scope, zval *object, char *name, int name_length, zend_bool silent tsrmls_dc);

zend_api zval *zend_read_static_property(zend_class_entry *scope, char *name, int name_length, zend_bool silent tsrmls_dc);

zend_read_property函式用於讀取物件的屬性,而zend_read_static_property則用於讀取靜態屬性。可以看出,靜態屬性是直接儲存在類上的,用具體的物件無關。

silent引數:

如果所查的屬性不存在,那麼此函式將返回is_null型別的zval。

更新物件的屬性:

zend_api void zend_update_property(zend_class_entry *scope, zval *object, char *name, int name_length, zval *value tsrmls_dc);

zend_api int zend_update_static_property(zend_class_entry *scope, char *name, int name_length, zval *value tsrmls_dc);

zend_update_property用來更新物件的屬性,zend_update_static_property用來更新類的靜態屬性。如果物件或者類中沒有相關的屬性,函式將自動的新增上。

假設我們已經在擴充套件中定義好下面的類:

class baby

}zend_method(baby, __construct)

zend_update_property(ce, getthis(), "age", sizeof("age")-1, age tsrmls_cc);

zend_update_static_property(ce, "area", sizeof("area")-1, area tsrmls_cc);

age = null;

area = null;

age = zend_read_property(ce, getthis(), "age", sizeof("age")-1, 0 tsrmls_dc);

php_var_dump(&age, 1 tsrmls_cc);

area = zend_read_static_property(ce, "area", sizeof("area")-1, 0 tsrmls_dc);

php_var_dump(&area, 1 tsrmls_cc);

}

zend_api void zend_update_property_null(zend_class_entry *scope, zval *object, char *name, int name_length tsrmls_dc);

zend_api void zend_update_property_bool(zend_class_entry *scope, zval *object, char *name, int name_length, long value tsrmls_dc);

zend_api void zend_update_property_long(zend_class_entry *scope, zval *object, char *name, int name_length, long value tsrmls_dc);

zend_api void zend_update_property_double(zend_class_entry *scope, zval *object, char *name, int name_length, double value tsrmls_dc);

zend_api void zend_update_property_string(zend_class_entry *scope, zval *object, char *name, int name_length, const char *value tsrmls_dc);

zend_api void zend_update_property_stringl(zend_class_entry *scope, zval *object, char *name, int name_length, const char *value, int value_length tsrmls_dc);

zend_api int zend_update_static_property_null(zend_class_entry *scope, char *name, int name_length tsrmls_dc);

zend_api int zend_update_static_property_bool(zend_class_entry *scope, char *name, int name_length, long value tsrmls_dc);

zend_api int zend_update_static_property_long(zend_class_entry *scope, char *name, int name_length, long value tsrmls_dc);

zend_api int zend_update_static_property_double(zend_class_entry *scope, char *name, int name_length, double value tsrmls_dc);

zend_api int zend_update_static_property_string(zend_class_entry *scope, char *name, int name_length, const char *value tsrmls_dc);

zend_api int zend_update_static_property_stringl(zend_class_entry *scope, char *name, int name_length, const char *value, int value_length tsrmls_dc);

2 物件及其屬性

r語言的基礎性概念 物件 向量 vector 陣列 array 矩陣 matrix 資料框 data frame 列表 list as.資料型別 是修改資料型別的函式 數值型 a 100 a 100 物件a 為字元型 a as.numeric a 轉化為數值型別 複數型 a 100 11i a 10...

物件導向(一) 物件屬性

物件屬性型別 每個物件都是基於乙個引用型別建立的 1.資料屬性 2.訪問器屬性 4個特性 1.configurable 能否delete屬性從而重新定義屬性 能否修改屬性的特性 能否把屬性改為訪問器屬性 2.enumerable 能否用for in迴圈返回屬性 3.writable 能否修改屬性的值...

物件導向(一) 物件屬性

物件屬性型別 每個物件都是基於乙個引用型別建立的 1.資料屬性 2.訪問器屬性 4個特性 1.configurable 能否delete屬性從而重新定義屬性 能否修改屬性的特性 能否把屬性改為訪問器屬性 2.enumerable 能否用for in迴圈返回屬性 3.writable 能否修改屬性的值...