Skip to content

Commit 1126232

Browse files
committedJul 18, 2023
Deprecate calling get_class() and get_parent_class() without arguments
1 parent 4acf008 commit 1126232

9 files changed

+77
-15
lines changed
 

‎Zend/tests/009.phpt

+14-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ class foo2 extends foo {
2323
$f1 = new foo;
2424
$f2 = new foo2;
2525

26-
$f1->bar();
26+
set_error_handler(function ($severity, $message, $file, $line) {
27+
throw new Exception($message);
28+
});
29+
try {
30+
$f1->bar();
31+
} catch (Exception $e) {
32+
echo $e->getMessage() . "\n";
33+
}
34+
set_error_handler(null);
35+
2736
$f2->bar();
2837

2938
try {
@@ -44,8 +53,10 @@ $f1->testNull();
4453

4554
echo "Done\n";
4655
?>
47-
--EXPECT--
48-
string(3) "foo"
56+
--EXPECTF--
57+
Calling get_class() without arguments is deprecated
58+
59+
Deprecated: Calling get_class() without arguments is deprecated in %s on line %d
4960
string(3) "foo"
5061
get_class() without arguments must be called from within a class
5162
get_class(): Argument #1 ($object) must be of type object, string given

‎Zend/tests/010.phpt

+17-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@ class foo implements i {
1515

1616
class bar extends foo {
1717
function test_bar() {
18-
var_dump(get_parent_class());
18+
var_dump(get_parent_class($this));
1919
}
2020
}
2121

2222
$bar = new bar;
2323
$foo = new foo;
2424

25+
set_error_handler(function ($severity, $message, $file, $line) {
26+
throw new Exception($message);
27+
});
28+
try {
29+
$foo->test();
30+
} catch (Exception $e) {
31+
echo $e->getMessage() . "\n";
32+
}
33+
set_error_handler(null);
34+
2535
$foo->test();
2636
$bar->test();
2737
$bar->test_bar();
@@ -66,8 +76,13 @@ try {
6676

6777
echo "Done\n";
6878
?>
69-
--EXPECT--
79+
--EXPECTF--
80+
Calling get_parent_class() without arguments is deprecated
81+
82+
Deprecated: Calling get_parent_class() without arguments is deprecated in %s on line %d
7083
bool(false)
84+
85+
Deprecated: Calling get_parent_class() without arguments is deprecated in %s on line %d
7186
bool(false)
7287
string(3) "foo"
7388
string(3) "foo"

‎Zend/tests/class_alias_017.phpt

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ baz::test();
2626
bar::test();
2727

2828
?>
29-
--EXPECT--
29+
--EXPECTF--
3030
foo
3131
baz
32+
33+
Deprecated: Calling get_class() without arguments is deprecated in %s on line %d
3234
foo
35+
36+
Deprecated: Calling get_class() without arguments is deprecated in %s on line %d
3337
foo

‎Zend/tests/closure_058.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ Closure 058: Closure scope and object
44
<?php
55
class A {
66
static function foo() {
7-
return function () {var_dump(get_class(),get_called_class());};
7+
return function () {var_dump(self::class,get_called_class());};
88
}
99
function bar() {
10-
return function () {var_dump(get_class(),get_called_class(),$this);};
10+
return function () {var_dump(self::class,get_called_class(),$this);};
1111
}
1212
}
1313
$z = "call_user_func";

‎Zend/tests/generators/generator_static_method.phpt

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ foreach (ExtendedTest::gen() as $i) {
2121
}
2222

2323
?>
24-
--EXPECT--
24+
--EXPECTF--
25+
Deprecated: Calling get_class() without arguments is deprecated in %s on line %d
2526
string(4) "Test"
2627
string(12) "ExtendedTest"
2728
int(1)

‎Zend/tests/get_parent_class_001.phpt

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ $a = new foo;
2323
$a->foo();
2424

2525
?>
26-
--EXPECT--
26+
--EXPECTF--
27+
Deprecated: Calling get_parent_class() without arguments is deprecated in %s on line %d
2728
string(3) "bar"
29+
30+
Deprecated: Calling get_parent_class() without arguments is deprecated in %s on line %d
2831
bool(false)

‎Zend/zend_builtin_functions.c

+8
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,10 @@ ZEND_FUNCTION(get_class)
557557
zend_class_entry *scope = zend_get_executed_scope();
558558

559559
if (scope) {
560+
zend_error(E_DEPRECATED, "Calling get_class() without arguments is deprecated");
561+
if (UNEXPECTED(EG(exception))) {
562+
RETURN_THROWS();
563+
}
560564
RETURN_STR_COPY(scope->name);
561565
} else {
562566
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
@@ -596,6 +600,10 @@ ZEND_FUNCTION(get_parent_class)
596600
ZEND_PARSE_PARAMETERS_END();
597601

598602
if (!ce) {
603+
zend_error(E_DEPRECATED, "Calling get_parent_class() without arguments is deprecated");
604+
if (UNEXPECTED(EG(exception))) {
605+
RETURN_THROWS();
606+
}
599607
ce = zend_get_executed_scope();
600608
}
601609

‎Zend/zend_vm_def.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -9355,13 +9355,17 @@ ZEND_VM_COLD_CONST_HANDLER(191, ZEND_GET_CLASS, UNUSED|CONST|TMPVAR|CV, UNUSED)
93559355
USE_OPLINE
93569356

93579357
if (OP1_TYPE == IS_UNUSED) {
9358+
SAVE_OPLINE();
93589359
if (UNEXPECTED(!EX(func)->common.scope)) {
9359-
SAVE_OPLINE();
93609360
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
93619361
ZVAL_UNDEF(EX_VAR(opline->result.var));
93629362
HANDLE_EXCEPTION();
93639363
} else {
9364+
zend_error(E_DEPRECATED, "Calling get_class() without arguments is deprecated");
93649365
ZVAL_STR_COPY(EX_VAR(opline->result.var), EX(func)->common.scope->name);
9366+
if (UNEXPECTED(EG(exception))) {
9367+
HANDLE_EXCEPTION();
9368+
}
93659369
ZEND_VM_NEXT_OPCODE();
93669370
}
93679371
} else {

‎Zend/zend_vm_execute.h

+20-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.