Hello internals,

  this patch allows to access class constants by objects.
If noone objects i'll commit it on tuesday.

Example:

class Test
{
    const Foo = 'Bar';
}

$obj = new Test;

var_dump($obj::Foo);

-- 
Best regards,
 Marcus
Index: Zend/zend_language_parser.y
===================================================================
RCS file: /repository/ZendEngine2/zend_language_parser.y,v
retrieving revision 1.150
diff -u -p -d -r1.150 zend_language_parser.y
--- Zend/zend_language_parser.y 16 Sep 2004 05:43:29 -0000      1.150
+++ Zend/zend_language_parser.y 30 Sep 2004 19:14:40 -0000
@@ -608,6 +608,7 @@ expr_without_variable:      
        |       T_ARRAY '(' array_pair_list ')' { $$ = $3; }
        |       '`' encaps_list '`'             { zend_do_shell_exec(&$$, &$2 
TSRMLS_CC); }
        |       T_PRINT expr  { zend_do_print(&$$, &$2 TSRMLS_CC); }
+       |       variable T_PAAMAYIM_NEKUDOTAYIM T_STRING { 
zend_do_end_variable_parse(BP_VAR_R, 0 TSRMLS_CC); zend_do_fetch_constant(&$$, &$1, 
&$3, ZEND_RT TSRMLS_CC); }
 ;
 
 function_call:
Index: Zend/zend_vm_handlers.h
===================================================================
RCS file: /repository/ZendEngine2/zend_vm_handlers.h,v
retrieving revision 1.2
diff -u -p -d -r1.2 zend_vm_handlers.h
--- Zend/zend_vm_handlers.h     22 Sep 2004 08:45:21 -0000      1.2
+++ Zend/zend_vm_handlers.h     30 Sep 2004 19:14:43 -0000
@@ -2865,13 +2865,14 @@ ZEND_VM_HANDLER(ZEND_CLONE)
 }
 #endif
 
-#define ZEND_FETCH_CONSTANT_SPEC() OPDEF(ZEND_FETCH_CONSTANT, M_CONST_UNUSED, M_CONST)
+#define ZEND_FETCH_CONSTANT_SPEC() OPDEF(ZEND_FETCH_CONSTANT, M_CONST_TMP_VAR_UNUSED, 
M_CONST)
 #if HAVE_OP(ZEND_FETCH_CONSTANT)
 ZEND_VM_HANDLER(ZEND_FETCH_CONSTANT)
 {
        zend_op *opline = EX(opline);
        zend_class_entry *ce = NULL;
        zval **value;
+       zend_free_op free_op1;
 
        if (OP1_TYPE == IS_UNUSED) {
 /* This seems to be a reminant of namespaces
@@ -2895,16 +2896,21 @@ ZEND_VM_HANDLER(ZEND_FETCH_CONSTANT)
                ZEND_VM_NEXT_OPCODE();
        }
 
-       ce = EX_T(opline->op1.u.var).class_entry;
-
+       if (OP1_TYPE == IS_CONST) {
+               ce = EX_T(opline->op1.u.var).class_entry;
+       } else {
+               zval *obj = GET_OP1_ZVAL_PTR(BP_VAR_R);
+               ce = Z_OBJCE_P(obj);
+       }
        if (zend_hash_find(&ce->constants_table, opline->op2.u.constant.value.str.val, 
opline->op2.u.constant.value.str.len+1, (void **) &value) == SUCCESS) {
                zval_update_constant(value, (void *) 1 TSRMLS_CC);
                EX_T(opline->result.u.var).tmp_var = **value;
                zval_copy_ctor(&EX_T(opline->result.u.var).tmp_var);
        } else {
                zend_error_noreturn(E_ERROR, "Undefined class constant '%s'", 
opline->op2.u.constant.value.str.val);
        }
 
+       FREE_OP1();
        ZEND_VM_NEXT_OPCODE();
 }
 #endif
-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to