<code><span><span>class</span><span>Slash_Log</span> {</span><span>const</span> EMERGENCY = <span>1</span>; <span>const</span> ALERT = <span>2</span>; <span>const</span> CRITICAL = <span>3</span>; <span>const</span> FATAL = <span>3</span>; <span>const</span> ERROR = <span>4</span>; <span>const</span> WARN = <span>5</span>; <span>const</span> NOTICE = <span>6</span>; <span>const</span> INFO = <span>7</span>; <span>const</span> DEBUG = <span>8</span>; <span>public</span><span>static</span><span>$levels</span> = <span>array</span>( <span>self</span>::EMERGENCY => <span>1</span>, <span>self</span>::ALERT => <span>2</span>, <span>self</span>::CRITICAL => <span>3</span>, <span>self</span>::FATAL => <span>3</span>, <span>self</span>::ERROR => <span>4</span>, <span>self</span>::WARN => <span>5</span>, <span>self</span>::NOTICE => <span>6</span>, <span>self</span>::INFO => <span>7</span>, <span>self</span>::DEBUG => <span>8</span>, ); }</code>
<code>zend_class_entry ce; SLASH_INIT_CLASS_ENTRY(ce, SLASH_CN_LOG, slash_log_methods); slash_log_ce = zend_register_internal_class(&ce TSRMLS_CC); <span>// {{{ log level</span> zend_declare_class_constant_long(slash_log_ce, ZEND_STRL(SL_EMERGENCY_K), SL_EMERGENCY_V TSRMLS_CC); zend_declare_class_constant_long(slash_log_ce, ZEND_STRL(SL_ALERT_K), SL_ALERT_V TSRMLS_CC); zend_declare_class_constant_long(slash_log_ce, ZEND_STRL(SL_CRITICAL_K), SL_CRITICAL_V TSRMLS_CC); zend_declare_class_constant_long(slash_log_ce, ZEND_STRL(SL_ERROR_K), SL_ERROR_V TSRMLS_CC); zend_declare_class_constant_long(slash_log_ce, ZEND_STRL(SL_WARN_K), SL_WARN_V TSRMLS_CC); zend_declare_class_constant_long(slash_log_ce, ZEND_STRL(SL_NOTICE_K), SL_NOTICE_V TSRMLS_CC); zend_declare_class_constant_long(slash_log_ce, ZEND_STRL(SL_INFO_K), SL_INFO_V TSRMLS_CC); zend_declare_class_constant_long(slash_log_ce, ZEND_STRL(SL_DEBUG_K), SL_DEBUG_V TSRMLS_CC); <span>// }}}</span><span>// {{{ static property array</span> zend_declare_property_null(slash_log_ce, ZEND_STRL(SL_P_LEVELS), ZEND_ACC_PUBLIC|ZEND_ACC_STATIC TSRMLS_CC); zval *levels; MAKE_STD_ZVAL(levels); array_init(levels); add_index_stringl(levels, SL_EMERGENCY_V, ZEND_STRL(SL_EMERGENCY_K), <span>0</span>); add_index_stringl(levels, SL_ALERT_V, ZEND_STRL(SL_ALERT_K), <span>0</span>); add_index_stringl(levels, SL_CRITICAL_V, ZEND_STRL(SL_CRITICAL_K), <span>0</span>); add_index_stringl(levels, SL_ERROR_V, ZEND_STRL(SL_ERROR_K), <span>0</span>); add_index_stringl(levels, SL_WARN_V, ZEND_STRL(SL_WARN_K), <span>0</span>); add_index_stringl(levels, SL_NOTICE_V, ZEND_STRL(SL_NOTICE_K), <span>0</span>); add_index_stringl(levels, SL_INFO_V, ZEND_STRL(SL_INFO_K), <span>0</span>); add_index_stringl(levels, SL_DEBUG_V, ZEND_STRL(SL_DEBUG_K), <span>0</span>); zend_update_static_property(slash_log_ce, ZEND_STRL(SL_P_LEVELS), levels TSRMLS_CC); <span>// }}}</span></code>
참고(1) Extensions에 나와 있으므로 배열 속성을 직접 초기화할 수 없으므로 여기서는 null(zend_declare_property_null)로 초기화된 정적 속성을 정의한 다음 이 속성의 값을 해당 배열로 수정(zend_update_static_property)하여 public static $array 효과를 얻습니다.
해당 변수명에는 매크로가 정의되어 있어서 코드를 직접 복사하면 컴파일이 되지 않습니다
위 내용은 PHP 확장 개발 노트(3) 클래스의 정적 배열 속성 정의를 소개하며, 관련 내용을 포함하여 PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.