mirror of
https://github.com/php/php-src.git
synced 2025-01-27 06:03:45 +08:00
Allow self etc in eval / file scope
This fixes a regression from 16a9bc1ec2
.
Together with the recent closure related changes this should allow
all usages of self etc, while previously (in PHP 5) some things like
self::class did not work.
This commit is contained in:
parent
ab4ccffc4c
commit
6ef8ae65a2
@ -1,8 +1,10 @@
|
||||
--TEST--
|
||||
Accessing self::FOO outside a class
|
||||
Accessing self::FOO in a free function
|
||||
--FILE--
|
||||
<?php
|
||||
var_dump(self::FOO);
|
||||
function test() {
|
||||
var_dump(self::FOO);
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Cannot use "self" when no class scope is active in %s on line %d
|
||||
|
28
Zend/tests/self_in_eval.phpt
Normal file
28
Zend/tests/self_in_eval.phpt
Normal file
@ -0,0 +1,28 @@
|
||||
--TEST--
|
||||
self etc. can be used in eval() in a class scope
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class C {
|
||||
const FOO = 1;
|
||||
private static $bar = 2;
|
||||
public static function f() {
|
||||
eval(<<<'PHP'
|
||||
var_dump(self::FOO);
|
||||
var_dump(self::$bar);
|
||||
var_dump(self::class);
|
||||
var_dump(static::class);
|
||||
PHP
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
C::f();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
int(1)
|
||||
int(2)
|
||||
string(1) "C"
|
||||
string(1) "C"
|
||||
|
@ -1325,6 +1325,11 @@ static inline zend_bool zend_is_scope_known() /* {{{ */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!CG(active_op_array)->function_name) {
|
||||
/* A file/eval will be run in the including/eval'ing scope */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!CG(active_class_entry)) {
|
||||
/* Not being in a scope is a known scope */
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user