Do You PHP はてブロ

Do You PHPはてなからはてブロに移動しました

PROP_GET_LONG/PROP_SET_LONGマクロ


PEAR::CodeGen_PECLexamplesディレクトリにあるclass_properties.xmlから生成したCのソースコード(class_properties.c)には

  • PROP_GET_LONG
  • PROP_SET_LONG

というマクロっぽい名前が見つかります。動作を確認してみると、それぞれクラスのプロパティへのアクセサっぽいんですが、どうも他の拡張モジュールやPHPソースコード、Building Custom PHP Extensions

Building Custom Php Extensions

Building Custom Php Extensions

やExtending and Embedding PHP
Extending and Embedding PHP (Developer's Library)

Extending and Embedding PHP (Developer's Library)

にも見あたりません。。。
定義はどこだろ?と思っていたら、何てコトはない、PEAR::CodeGen_PECLで生成されたヘッダファイル(php_class_properties.h)にありました。。。orz

#define PROP_GET_LONG(name)    Z_LVAL_P(zend_read_property(_this_ce, _this_zval, #name, strlen(#name), 1 TSRMLS_CC))
#define PROP_SET_LONG(name, l) zend_update_property_long(_this_ce, _this_zval, #name, strlen(#name), l TSRMLS_CC)

#define PROP_GET_DOUBLE(name)    Z_DVAL_P(zend_read_property(_this_ce, _this_zval, #name, strlen(#name), 1 TSRMLS_CC))
#define PROP_SET_DOUBLE(name, d) zend_update_property_double(_this_ce, _this_zval, #name, strlen(#name), d TSRMLS_CC)

#define PROP_GET_STRING(name)    Z_STRVAL_P(zend_read_property(_this_ce, _this_zval, #name, strlen(#name), 1 TSRMLS_CC))
#define PROP_GET_STRLEN(name)    Z_STRLEN_P(zend_read_property(_this_ce, _this_zval, #name, strlen(#name), 1 TSRMLS_CC))
#define PROP_SET_STRING(name, s) zend_update_property_string(_this_ce, _this_zval, #name, strlen(#name), s TSRMLS_CC)
#define PROP_SET_STRINGL(name, s, l) zend_update_property_string(_this_ce, _this_zval, #name, strlen(#name), s, l TSRMLS_CC)

LONGの他、STRINGやSTRLEN(名前のまま。文字列長です)、STRINGL(文字列長を指定)もありました。これのお陰で、結構楽できそうです :-)