From 26d592a13a7c92ad535e9ede8264ccfb23c22612 Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Sat, 8 Sep 2012 00:41:43 -0500 Subject: [PATCH] "::class" Feature: * Added class scope checking for self,parent+static * Fixed tab/spaces in phpt file --- Zend/tests/class_name_scalar.phpt | 25 ++++++++++++------------- Zend/zend_compile.c | 9 +++++++++ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Zend/tests/class_name_scalar.phpt b/Zend/tests/class_name_scalar.phpt index 329984cc1c042..21257592216c7 100644 --- a/Zend/tests/class_name_scalar.phpt +++ b/Zend/tests/class_name_scalar.phpt @@ -4,7 +4,7 @@ class name as scaler from ::class keyword ---EXPECTF-- +--EXPECTF-- In NS string(11) "Foo\Bar\Moo" Top diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index a510e5fecdc5a..f341b75650dc2 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -2169,12 +2169,21 @@ void zend_resolve_class_name(znode *class_name, ulong fetch_type, int check_ns_n lctype = zend_get_class_fetch_type(lcname, strlen(lcname)); switch (lctype) { case ZEND_FETCH_CLASS_SELF: + if (!CG(active_class_entry)) { + zend_error(E_COMPILE_ERROR, "Cannot access self::class when no class scope is active"); + } tmp.op_type = IS_CONST; ZVAL_STRINGL(&tmp.u.constant, CG(active_class_entry)->name, strlen(CG(active_class_entry)->name), 1); *class_name = tmp; break; case ZEND_FETCH_CLASS_STATIC: + if (!CG(active_class_entry)) { + zend_error(E_COMPILE_ERROR, "Cannot access static::class when no class scope is active"); + } case ZEND_FETCH_CLASS_PARENT: + if (!CG(active_class_entry)) { + zend_error(E_COMPILE_ERROR, "Cannot access parent::class when no class scope is active"); + } opline = get_next_op(CG(active_op_array) TSRMLS_CC); opline->opcode = ZEND_DO_FCALL; opline->result.var = get_temporary_variable(CG(active_op_array));