Skip to content

Commit a015fa8

Browse files
committed
Fixed bug #65291 - get_defined_constants() crash with __CLASS__ in trait
1 parent 2b9d424 commit a015fa8

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ PHP NEWS
44

55
- Core.
66
. Improve fix for bug #63186 (compile failure on netbsd). (Matteo)
7+
. Fixed bug #65291 (get_defined_constants() causes PHP to crash in a very
8+
limited case). (Arpad)
79

810
- Session:
911
. Fixed bug #62129 (rfc1867 crashes php even though turned off). (gxd305 at

Zend/tests/bug65291.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #65291 - get_defined_constants() causes PHP to crash in a very limited case.
3+
--FILE--
4+
<?php
5+
6+
trait TestTrait
7+
{
8+
public static function testStaticFunction()
9+
{
10+
return __CLASS__;
11+
}
12+
}
13+
class Tester
14+
{
15+
use TestTrait;
16+
}
17+
18+
$foo = Tester::testStaticFunction();
19+
get_defined_constants();
20+
21+
echo $foo;
22+
?>
23+
--EXPECT--
24+
Tester

Zend/zend_builtin_functions.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,11 @@ static int add_constant_info(zend_constant *constant, void *arg TSRMLS_DC)
19261926
zval *name_array = (zval *)arg;
19271927
zval *const_val;
19281928

1929+
if (!constant->name) {
1930+
/* skip special constants */
1931+
return 0;
1932+
}
1933+
19291934
MAKE_STD_ZVAL(const_val);
19301935
*const_val = constant->value;
19311936
zval_copy_ctor(const_val);

0 commit comments

Comments
 (0)