mirror of
https://github.com/php/php-src.git
synced 2025-08-16 14:08:47 +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;
|
$f1 = new foo;
|
||||||
$f2 = new foo2;
|
$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();
|
$f2->bar();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -44,8 +53,10 @@ $f1->testNull();
|
||||||
|
|
||||||
echo "Done\n";
|
echo "Done\n";
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECTF--
|
||||||
string(3) "foo"
|
Calling get_class() without arguments is deprecated
|
||||||
|
|
||||||
|
Deprecated: Calling get_class() without arguments is deprecated in %s on line %d
|
||||||
string(3) "foo"
|
string(3) "foo"
|
||||||
get_class() without arguments must be called from within a class
|
get_class() without arguments must be called from within a class
|
||||||
get_class(): Argument #1 ($object) must be of type object, string given
|
get_class(): Argument #1 ($object) must be of type object, string given
|
||||||
|
|
|
@ -15,13 +15,23 @@ class foo implements i {
|
||||||
|
|
||||||
class bar extends foo {
|
class bar extends foo {
|
||||||
function test_bar() {
|
function test_bar() {
|
||||||
var_dump(get_parent_class());
|
var_dump(get_parent_class($this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$bar = new bar;
|
$bar = new bar;
|
||||||
$foo = new foo;
|
$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();
|
$foo->test();
|
||||||
$bar->test();
|
$bar->test();
|
||||||
$bar->test_bar();
|
$bar->test_bar();
|
||||||
|
@ -66,8 +76,13 @@ try {
|
||||||
|
|
||||||
echo "Done\n";
|
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)
|
bool(false)
|
||||||
|
|
||||||
|
Deprecated: Calling get_parent_class() without arguments is deprecated in %s on line %d
|
||||||
bool(false)
|
bool(false)
|
||||||
string(3) "foo"
|
string(3) "foo"
|
||||||
string(3) "foo"
|
string(3) "foo"
|
||||||
|
|
|
@ -26,8 +26,12 @@ baz::test();
|
||||||
bar::test();
|
bar::test();
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECTF--
|
||||||
foo
|
foo
|
||||||
baz
|
baz
|
||||||
|
|
||||||
|
Deprecated: Calling get_class() without arguments is deprecated in %s on line %d
|
||||||
foo
|
foo
|
||||||
|
|
||||||
|
Deprecated: Calling get_class() without arguments is deprecated in %s on line %d
|
||||||
foo
|
foo
|
||||||
|
|
|
@ -4,10 +4,10 @@ Closure 058: Closure scope and object
|
||||||
<?php
|
<?php
|
||||||
class A {
|
class A {
|
||||||
static function foo() {
|
static function foo() {
|
||||||
return function () {var_dump(get_class(),get_called_class());};
|
return function () {var_dump(self::class,get_called_class());};
|
||||||
}
|
}
|
||||||
function bar() {
|
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";
|
$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(4) "Test"
|
||||||
string(12) "ExtendedTest"
|
string(12) "ExtendedTest"
|
||||||
int(1)
|
int(1)
|
||||||
|
|
|
@ -23,6 +23,9 @@ $a = new foo;
|
||||||
$a->foo();
|
$a->foo();
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECTF--
|
||||||
|
Deprecated: Calling get_parent_class() without arguments is deprecated in %s on line %d
|
||||||
string(3) "bar"
|
string(3) "bar"
|
||||||
|
|
||||||
|
Deprecated: Calling get_parent_class() without arguments is deprecated in %s on line %d
|
||||||
bool(false)
|
bool(false)
|
||||||
|
|
|
@ -557,6 +557,10 @@ ZEND_FUNCTION(get_class)
|
||||||
zend_class_entry *scope = zend_get_executed_scope();
|
zend_class_entry *scope = zend_get_executed_scope();
|
||||||
|
|
||||||
if (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);
|
RETURN_STR_COPY(scope->name);
|
||||||
} else {
|
} else {
|
||||||
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
|
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();
|
ZEND_PARSE_PARAMETERS_END();
|
||||||
|
|
||||||
if (!ce) {
|
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();
|
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
|
USE_OPLINE
|
||||||
|
|
||||||
if (OP1_TYPE == IS_UNUSED) {
|
if (OP1_TYPE == IS_UNUSED) {
|
||||||
|
SAVE_OPLINE();
|
||||||
if (UNEXPECTED(!EX(func)->common.scope)) {
|
if (UNEXPECTED(!EX(func)->common.scope)) {
|
||||||
SAVE_OPLINE();
|
|
||||||
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
|
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
|
||||||
ZVAL_UNDEF(EX_VAR(opline->result.var));
|
ZVAL_UNDEF(EX_VAR(opline->result.var));
|
||||||
HANDLE_EXCEPTION();
|
HANDLE_EXCEPTION();
|
||||||
} else {
|
} 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);
|
ZVAL_STR_COPY(EX_VAR(opline->result.var), EX(func)->common.scope->name);
|
||||||
|
if (UNEXPECTED(EG(exception))) {
|
||||||
|
HANDLE_EXCEPTION();
|
||||||
|
}
|
||||||
ZEND_VM_NEXT_OPCODE();
|
ZEND_VM_NEXT_OPCODE();
|
||||||
}
|
}
|
||||||
} else {
|
} 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
|
USE_OPLINE
|
||||||
|
|
||||||
if (IS_CONST == IS_UNUSED) {
|
if (IS_CONST == IS_UNUSED) {
|
||||||
|
SAVE_OPLINE();
|
||||||
if (UNEXPECTED(!EX(func)->common.scope)) {
|
if (UNEXPECTED(!EX(func)->common.scope)) {
|
||||||
SAVE_OPLINE();
|
|
||||||
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
|
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
|
||||||
ZVAL_UNDEF(EX_VAR(opline->result.var));
|
ZVAL_UNDEF(EX_VAR(opline->result.var));
|
||||||
HANDLE_EXCEPTION();
|
HANDLE_EXCEPTION();
|
||||||
} else {
|
} 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);
|
ZVAL_STR_COPY(EX_VAR(opline->result.var), EX(func)->common.scope->name);
|
||||||
|
if (UNEXPECTED(EG(exception))) {
|
||||||
|
HANDLE_EXCEPTION();
|
||||||
|
}
|
||||||
ZEND_VM_NEXT_OPCODE();
|
ZEND_VM_NEXT_OPCODE();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -18217,13 +18221,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_GET_CLASS_SPEC_TMPVAR_UNUSED_H
|
||||||
USE_OPLINE
|
USE_OPLINE
|
||||||
|
|
||||||
if ((IS_TMP_VAR|IS_VAR) == IS_UNUSED) {
|
if ((IS_TMP_VAR|IS_VAR) == IS_UNUSED) {
|
||||||
|
SAVE_OPLINE();
|
||||||
if (UNEXPECTED(!EX(func)->common.scope)) {
|
if (UNEXPECTED(!EX(func)->common.scope)) {
|
||||||
SAVE_OPLINE();
|
|
||||||
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
|
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
|
||||||
ZVAL_UNDEF(EX_VAR(opline->result.var));
|
ZVAL_UNDEF(EX_VAR(opline->result.var));
|
||||||
HANDLE_EXCEPTION();
|
HANDLE_EXCEPTION();
|
||||||
} else {
|
} 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);
|
ZVAL_STR_COPY(EX_VAR(opline->result.var), EX(func)->common.scope->name);
|
||||||
|
if (UNEXPECTED(EG(exception))) {
|
||||||
|
HANDLE_EXCEPTION();
|
||||||
|
}
|
||||||
ZEND_VM_NEXT_OPCODE();
|
ZEND_VM_NEXT_OPCODE();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -37032,13 +37040,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_GET_CLASS_SPEC_UNUSED_UNUSED_H
|
||||||
USE_OPLINE
|
USE_OPLINE
|
||||||
|
|
||||||
if (IS_UNUSED == IS_UNUSED) {
|
if (IS_UNUSED == IS_UNUSED) {
|
||||||
|
SAVE_OPLINE();
|
||||||
if (UNEXPECTED(!EX(func)->common.scope)) {
|
if (UNEXPECTED(!EX(func)->common.scope)) {
|
||||||
SAVE_OPLINE();
|
|
||||||
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
|
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
|
||||||
ZVAL_UNDEF(EX_VAR(opline->result.var));
|
ZVAL_UNDEF(EX_VAR(opline->result.var));
|
||||||
HANDLE_EXCEPTION();
|
HANDLE_EXCEPTION();
|
||||||
} else {
|
} 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);
|
ZVAL_STR_COPY(EX_VAR(opline->result.var), EX(func)->common.scope->name);
|
||||||
|
if (UNEXPECTED(EG(exception))) {
|
||||||
|
HANDLE_EXCEPTION();
|
||||||
|
}
|
||||||
ZEND_VM_NEXT_OPCODE();
|
ZEND_VM_NEXT_OPCODE();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -49848,13 +49860,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_GET_CLASS_SPEC_CV_UNUSED_HANDL
|
||||||
USE_OPLINE
|
USE_OPLINE
|
||||||
|
|
||||||
if (IS_CV == IS_UNUSED) {
|
if (IS_CV == IS_UNUSED) {
|
||||||
|
SAVE_OPLINE();
|
||||||
if (UNEXPECTED(!EX(func)->common.scope)) {
|
if (UNEXPECTED(!EX(func)->common.scope)) {
|
||||||
SAVE_OPLINE();
|
|
||||||
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
|
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
|
||||||
ZVAL_UNDEF(EX_VAR(opline->result.var));
|
ZVAL_UNDEF(EX_VAR(opline->result.var));
|
||||||
HANDLE_EXCEPTION();
|
HANDLE_EXCEPTION();
|
||||||
} else {
|
} 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);
|
ZVAL_STR_COPY(EX_VAR(opline->result.var), EX(func)->common.scope->name);
|
||||||
|
if (UNEXPECTED(EG(exception))) {
|
||||||
|
HANDLE_EXCEPTION();
|
||||||
|
}
|
||||||
ZEND_VM_NEXT_OPCODE();
|
ZEND_VM_NEXT_OPCODE();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue