Permalink
Browse files

"::class" Feature:

* Added class scope checking for self,parent+static
* Fixed tab/spaces in phpt file
  • Loading branch information...
1 parent 76703a0 commit 26d592a13a7c92ad535e9ede8264ccfb23c22612 @ralphschindler committed Sep 8, 2012
Showing with 21 additions and 13 deletions.
  1. +12 −13 Zend/tests/class_name_scalar.phpt
  2. +9 −0 Zend/zend_compile.c
View
25 Zend/tests/class_name_scalar.phpt
@@ -4,7 +4,7 @@ class name as scaler from ::class keyword
<?php
namespace Foo\Bar {
- class One {}
+ class One {}
class Two extends One {
public static function run() {
var_dump(self::class);
@@ -15,28 +15,27 @@ namespace Foo\Bar {
}
class Three extends Two {}
echo "In NS\n";
- var_dump(Moo::CLASS); // resolve in namespace
+ var_dump(Moo::CLASS); // resolve in namespace
}
namespace {
- use Bee\Bop as Moo,
- Foo\Bar\One;
+ use Bee\Bop as Moo,
+ Foo\Bar\One;
echo "Top\n";
- var_dump(One::class); // resolve from use
- var_dump(Boo::class); // resolve in global namespace
- var_dump(Moo::CLASS); // resolve from use as
- var_dump(\Moo::Class); // resolve fully qualified
- $class = One::class; // assign class as scalar to var
- $x = new $class; // create new class from original scalar assignment
- var_dump($x);
+ var_dump(One::class); // resolve from use
+ var_dump(Boo::class); // resolve in global namespace
+ var_dump(Moo::CLASS); // resolve from use as
+ var_dump(\Moo::Class); // resolve fully qualified
+ $class = One::class; // assign class as scalar to var
+ $x = new $class; // create new class from original scalar assignment
+ var_dump($x);
Foo\Bar\Two::run(); // resolve runtime lookups
echo "Parent\n";
Foo\Bar\Three::run(); // resolve runtime lookups with inheritance
}
-
?>
---EXPECTF--
+--EXPECTF--
In NS
string(11) "Foo\Bar\Moo"
Top
View
9 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));

0 comments on commit 26d592a

Please sign in to comment.