From 75b3d4e697077b311adfa6ccf081a6fb45feb405 Mon Sep 17 00:00:00 2001 From: Jan Dolecek Date: Sun, 11 Dec 2011 23:57:02 +0100 Subject: [PATCH] added magic constants 'className' and 'class' --- Zend/zend_compile.c | 5 +++-- Zend/zend_compile.h | 2 ++ Zend/zend_language_parser.y | 2 ++ Zend/zend_vm_def.h | 8 +++++++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index c325a7e..ca30baf 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -3918,7 +3918,7 @@ void zend_do_fetch_constant(znode *result, znode *constant_container, znode *con ulong fetch_type = 0; if (constant_container) { - switch (mode) { + switch (mode & ZEND_CONSTANT_BASIC) { case ZEND_CT: /* this is a class constant */ type = zend_get_class_fetch_type(Z_STRVAL(constant_container->u.constant), Z_STRLEN(constant_container->u.constant)); @@ -3946,6 +3946,7 @@ void zend_do_fetch_constant(znode *result, znode *constant_container, znode *con opline->result.u.var = get_temporary_variable(CG(active_op_array)); opline->op1 = *constant_container; opline->op2 = *constant_name; + opline->extended_value |= mode; *result = opline->result; break; } @@ -3953,7 +3954,7 @@ void zend_do_fetch_constant(znode *result, znode *constant_container, znode *con } /* namespace constant */ /* only one that did not contain \ from the start can be converted to string if unknown */ - switch (mode) { + switch (mode & ZEND_CONSTANT_BASIC) { case ZEND_CT: compound = memchr(Z_STRVAL(constant_name->u.constant), '\\', Z_STRLEN(constant_name->u.constant)); /* this is a namespace constant, or an unprefixed constant */ diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index 15f24df..e9c4d5f 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -687,6 +687,8 @@ int zendlex(znode *zendlval TSRMLS_DC); #define ZEND_CT (1<<0) #define ZEND_RT (1<<1) +#define ZEND_CONSTANT_BASIC ZEND_CT | ZEND_RT +#define ZEND_CONSTANT_CLASS (1<<2) #define ZEND_FETCH_STANDARD 0x00000000 #define ZEND_FETCH_ADD_LOCK 0x08000000 diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y index 1753e97..abeaa27 100644 --- a/Zend/zend_language_parser.y +++ b/Zend/zend_language_parser.y @@ -997,6 +997,8 @@ isset_variables: class_constant: class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING { zend_do_fetch_constant(&$$, &$1, &$3, ZEND_RT, 0 TSRMLS_CC); } | variable_class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING { zend_do_fetch_constant(&$$, &$1, &$3, ZEND_RT, 0 TSRMLS_CC); } + | class_name T_PAAMAYIM_NEKUDOTAYIM T_CLASS { zend_do_fetch_constant(&$$, &$1, &$3, ZEND_RT | ZEND_CONSTANT_CLASS, 0 TSRMLS_CC); } + | variable_class_name T_PAAMAYIM_NEKUDOTAYIM T_CLASS { zend_do_fetch_constant(&$$, &$1, &$3, ZEND_RT | ZEND_CONSTANT_CLASS, 0 TSRMLS_CC); } ; %% diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 2b0cbdb..f2e9f54 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -3050,7 +3050,13 @@ ZEND_VM_HANDLER(99, ZEND_FETCH_CONSTANT, VAR|CONST|UNUSED, CONST) ce = EX_T(opline->op1.u.var).class_entry; } - if (zend_hash_find(&ce->constants_table, Z_STRVAL(opline->op2.u.constant), Z_STRLEN(opline->op2.u.constant)+1, (void **) &value) == SUCCESS) { + if (opline->extended_value & ZEND_CONSTANT_CLASS) { + zend_reflection_class_factory(ce, &EX_T(opline->result.u.var).tmp_var TSRMLS_CC); + + } else if (Z_STRLEN(opline->op2.u.constant) == 9 && !memcmp(Z_STRVAL(opline->op2.u.constant), "className", 10)) { + ZVAL_STRING(&EX_T(opline->result.u.var).tmp_var, ce->name, 1); + + } else if (zend_hash_find(&ce->constants_table, Z_STRVAL(opline->op2.u.constant), Z_STRLEN(opline->op2.u.constant)+1, (void **) &value) == SUCCESS) { if (Z_TYPE_PP(value) == IS_CONSTANT_ARRAY || (Z_TYPE_PP(value) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) { zend_class_entry *old_scope = EG(scope); -- 1.7.0.4