mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Deprecate calling get_class() and get_parent_class() without arguments
This commit is contained in:
parent
4acf0084dc
commit
1126232053
9 changed files with 77 additions and 15 deletions
|
@ -23,7 +23,16 @@ class foo2 extends foo {
|
|||
$f1 = new foo;
|
||||
$f2 = new foo2;
|
||||
|
||||
$f1->bar();
|
||||
set_error_handler(function ($severity, $message, $file, $line) {
|
||||
throw new Exception($message);
|
||||
});
|
||||
try {
|
||||
$f1->bar();
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
set_error_handler(null);
|
||||
|
||||
$f2->bar();
|
||||
|
||||
try {
|
||||
|
@ -44,8 +53,10 @@ $f1->testNull();
|
|||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
string(3) "foo"
|
||||
--EXPECTF--
|
||||
Calling get_class() without arguments is deprecated
|
||||
|
||||
Deprecated: Calling get_class() without arguments is deprecated in %s on line %d
|
||||
string(3) "foo"
|
||||
get_class() without arguments must be called from within a class
|
||||
get_class(): Argument #1 ($object) must be of type object, string given
|
||||
|
|
|
@ -15,13 +15,23 @@ class foo implements i {
|
|||
|
||||
class bar extends foo {
|
||||
function test_bar() {
|
||||
var_dump(get_parent_class());
|
||||
var_dump(get_parent_class($this));
|
||||
}
|
||||
}
|
||||
|
||||
$bar = new bar;
|
||||
$foo = new foo;
|
||||
|
||||
set_error_handler(function ($severity, $message, $file, $line) {
|
||||
throw new Exception($message);
|
||||
});
|
||||
try {
|
||||
$foo->test();
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
set_error_handler(null);
|
||||
|
||||
$foo->test();
|
||||
$bar->test();
|
||||
$bar->test_bar();
|
||||
|
@ -66,8 +76,13 @@ try {
|
|||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
Calling get_parent_class() without arguments is deprecated
|
||||
|
||||
Deprecated: Calling get_parent_class() without arguments is deprecated in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Deprecated: Calling get_parent_class() without arguments is deprecated in %s on line %d
|
||||
bool(false)
|
||||
string(3) "foo"
|
||||
string(3) "foo"
|
||||
|
|
|
@ -26,8 +26,12 @@ baz::test();
|
|||
bar::test();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
foo
|
||||
baz
|
||||
|
||||
Deprecated: Calling get_class() without arguments is deprecated in %s on line %d
|
||||
foo
|
||||
|
||||
Deprecated: Calling get_class() without arguments is deprecated in %s on line %d
|
||||
foo
|
||||
|
|
|
@ -4,10 +4,10 @@ Closure 058: Closure scope and object
|
|||
<?php
|
||||
class A {
|
||||
static function foo() {
|
||||
return function () {var_dump(get_class(),get_called_class());};
|
||||
return function () {var_dump(self::class,get_called_class());};
|
||||
}
|
||||
function bar() {
|
||||
return function () {var_dump(get_class(),get_called_class(),$this);};
|
||||
return function () {var_dump(self::class,get_called_class(),$this);};
|
||||
}
|
||||
}
|
||||
$z = "call_user_func";
|
||||
|
|
|
@ -21,7 +21,8 @@ foreach (ExtendedTest::gen() as $i) {
|
|||
}
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
Deprecated: Calling get_class() without arguments is deprecated in %s on line %d
|
||||
string(4) "Test"
|
||||
string(12) "ExtendedTest"
|
||||
int(1)
|
||||
|
|
|
@ -23,6 +23,9 @@ $a = new foo;
|
|||
$a->foo();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
Deprecated: Calling get_parent_class() without arguments is deprecated in %s on line %d
|
||||
string(3) "bar"
|
||||
|
||||
Deprecated: Calling get_parent_class() without arguments is deprecated in %s on line %d
|
||||
bool(false)
|
||||
|
|
|
@ -557,6 +557,10 @@ ZEND_FUNCTION(get_class)
|
|||
zend_class_entry *scope = zend_get_executed_scope();
|
||||
|
||||
if (scope) {
|
||||
zend_error(E_DEPRECATED, "Calling get_class() without arguments is deprecated");
|
||||
if (UNEXPECTED(EG(exception))) {
|
||||
RETURN_THROWS();
|
||||
}
|
||||
RETURN_STR_COPY(scope->name);
|
||||
} else {
|
||||
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
|
||||
|
@ -596,6 +600,10 @@ ZEND_FUNCTION(get_parent_class)
|
|||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
if (!ce) {
|
||||
zend_error(E_DEPRECATED, "Calling get_parent_class() without arguments is deprecated");
|
||||
if (UNEXPECTED(EG(exception))) {
|
||||
RETURN_THROWS();
|
||||
}
|
||||
ce = zend_get_executed_scope();
|
||||
}
|
||||
|
||||
|
|
|
@ -9355,13 +9355,17 @@ ZEND_VM_COLD_CONST_HANDLER(191, ZEND_GET_CLASS, UNUSED|CONST|TMPVAR|CV, UNUSED)
|
|||
USE_OPLINE
|
||||
|
||||
if (OP1_TYPE == IS_UNUSED) {
|
||||
SAVE_OPLINE();
|
||||
if (UNEXPECTED(!EX(func)->common.scope)) {
|
||||
SAVE_OPLINE();
|
||||
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
|
||||
ZVAL_UNDEF(EX_VAR(opline->result.var));
|
||||
HANDLE_EXCEPTION();
|
||||
} else {
|
||||
zend_error(E_DEPRECATED, "Calling get_class() without arguments is deprecated");
|
||||
ZVAL_STR_COPY(EX_VAR(opline->result.var), EX(func)->common.scope->name);
|
||||
if (UNEXPECTED(EG(exception))) {
|
||||
HANDLE_EXCEPTION();
|
||||
}
|
||||
ZEND_VM_NEXT_OPCODE();
|
||||
}
|
||||
} else {
|
||||
|
|
24
Zend/zend_vm_execute.h
generated
24
Zend/zend_vm_execute.h
generated
|
@ -10953,13 +10953,17 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_GET_CLASS_SPEC_CO
|
|||
USE_OPLINE
|
||||
|
||||
if (IS_CONST == IS_UNUSED) {
|
||||
SAVE_OPLINE();
|
||||
if (UNEXPECTED(!EX(func)->common.scope)) {
|
||||
SAVE_OPLINE();
|
||||
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
|
||||
ZVAL_UNDEF(EX_VAR(opline->result.var));
|
||||
HANDLE_EXCEPTION();
|
||||
} else {
|
||||
zend_error(E_DEPRECATED, "Calling get_class() without arguments is deprecated");
|
||||
ZVAL_STR_COPY(EX_VAR(opline->result.var), EX(func)->common.scope->name);
|
||||
if (UNEXPECTED(EG(exception))) {
|
||||
HANDLE_EXCEPTION();
|
||||
}
|
||||
ZEND_VM_NEXT_OPCODE();
|
||||
}
|
||||
} else {
|
||||
|
@ -18217,13 +18221,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_GET_CLASS_SPEC_TMPVAR_UNUSED_H
|
|||
USE_OPLINE
|
||||
|
||||
if ((IS_TMP_VAR|IS_VAR) == IS_UNUSED) {
|
||||
SAVE_OPLINE();
|
||||
if (UNEXPECTED(!EX(func)->common.scope)) {
|
||||
SAVE_OPLINE();
|
||||
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
|
||||
ZVAL_UNDEF(EX_VAR(opline->result.var));
|
||||
HANDLE_EXCEPTION();
|
||||
} else {
|
||||
zend_error(E_DEPRECATED, "Calling get_class() without arguments is deprecated");
|
||||
ZVAL_STR_COPY(EX_VAR(opline->result.var), EX(func)->common.scope->name);
|
||||
if (UNEXPECTED(EG(exception))) {
|
||||
HANDLE_EXCEPTION();
|
||||
}
|
||||
ZEND_VM_NEXT_OPCODE();
|
||||
}
|
||||
} else {
|
||||
|
@ -37032,13 +37040,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_GET_CLASS_SPEC_UNUSED_UNUSED_H
|
|||
USE_OPLINE
|
||||
|
||||
if (IS_UNUSED == IS_UNUSED) {
|
||||
SAVE_OPLINE();
|
||||
if (UNEXPECTED(!EX(func)->common.scope)) {
|
||||
SAVE_OPLINE();
|
||||
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
|
||||
ZVAL_UNDEF(EX_VAR(opline->result.var));
|
||||
HANDLE_EXCEPTION();
|
||||
} else {
|
||||
zend_error(E_DEPRECATED, "Calling get_class() without arguments is deprecated");
|
||||
ZVAL_STR_COPY(EX_VAR(opline->result.var), EX(func)->common.scope->name);
|
||||
if (UNEXPECTED(EG(exception))) {
|
||||
HANDLE_EXCEPTION();
|
||||
}
|
||||
ZEND_VM_NEXT_OPCODE();
|
||||
}
|
||||
} else {
|
||||
|
@ -49848,13 +49860,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_GET_CLASS_SPEC_CV_UNUSED_HANDL
|
|||
USE_OPLINE
|
||||
|
||||
if (IS_CV == IS_UNUSED) {
|
||||
SAVE_OPLINE();
|
||||
if (UNEXPECTED(!EX(func)->common.scope)) {
|
||||
SAVE_OPLINE();
|
||||
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
|
||||
ZVAL_UNDEF(EX_VAR(opline->result.var));
|
||||
HANDLE_EXCEPTION();
|
||||
} else {
|
||||
zend_error(E_DEPRECATED, "Calling get_class() without arguments is deprecated");
|
||||
ZVAL_STR_COPY(EX_VAR(opline->result.var), EX(func)->common.scope->name);
|
||||
if (UNEXPECTED(EG(exception))) {
|
||||
HANDLE_EXCEPTION();
|
||||
}
|
||||
ZEND_VM_NEXT_OPCODE();
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue