Skip to content

Commit 5f7040f

Browse files
committed
Improve error message for deprecated methods
1 parent 767a77a commit 5f7040f

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Test that a notice is thrown for deprecated methods
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('zend-test')) {
6+
die('skip zend-test extension not loaded');
7+
}
8+
--FILE--
9+
<?php
10+
11+
set_error_handler(function($code, $msg) {
12+
throw new Error($msg);
13+
});
14+
15+
$test = new _ZendTestClass();
16+
17+
try {
18+
echo $test;
19+
} catch (Error $e) {
20+
echo $e->getMessage(), "\n";
21+
}
22+
23+
?>
24+
--EXPECT--
25+
Method _ZendTestClass::__toString() is deprecated

Zend/zend_execute.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,10 +1504,14 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_wrong_property_read(z
15041504

15051505
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_deprecated_function(const zend_function *fbc)
15061506
{
1507-
zend_error(E_DEPRECATED, "Function %s%s%s() is deprecated",
1508-
fbc->common.scope ? ZSTR_VAL(fbc->common.scope->name) : "",
1509-
fbc->common.scope ? "::" : "",
1510-
ZSTR_VAL(fbc->common.function_name));
1507+
if (fbc->common.scope) {
1508+
zend_error(E_DEPRECATED, "Method %s::%s() is deprecated",
1509+
ZSTR_VAL(fbc->common.scope->name),
1510+
ZSTR_VAL(fbc->common.function_name)
1511+
);
1512+
} else {
1513+
zend_error(E_DEPRECATED, "Function %s() is deprecated", ZSTR_VAL(fbc->common.function_name));
1514+
}
15111515
}
15121516

15131517
static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim, zval *value OPLINE_DC EXECUTE_DATA_DC)

0 commit comments

Comments
 (0)