Skip to content

Commit 5bff128

Browse files
committed
Merge branch 'PHP-5.4' of https://git.php.net/repository/php-src into PHP-5.4
* 'PHP-5.4' of https://git.php.net/repository/php-src: Fixed bug #61759 (class_alias() should accept classes with leading backslashes). (Julien) Fixed bug #61759 (class_alias() should accept classes with leading backslashes). (Julien) Avoid compiler warning Fix bug #65579 (Using traits with get_class_methods causes segfault).
2 parents 1fdcc70 + dfc6feb commit 5bff128

File tree

4 files changed

+49
-17
lines changed

4 files changed

+49
-17
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ PHP NEWS
33
?? ??? 2013, PHP 5.4.20
44

55
- Core:
6+
. Fixed bug #65579 (Using traits with get_class_methods causes segfault).
7+
(Adam)
68
. Fixed bug #65490 (Duplicate calls to get lineno & filename for
79
DTRACE_FUNCTION_*). (Chris Jones)
810
. Fixed bug #65483 (quoted-printable encode stream filter incorrectly encoding
@@ -18,6 +20,8 @@ PHP NEWS
1820
. Fixed bug #65225 (PHP_BINARY incorrectly set). (Patrick Allaert)
1921
. Improved fix for bug #63186 (compile failure on netbsd). (Matteo)
2022
. Fixed bug #62692 (PHP fails to build with DTrace). (Chris Jones, Kris Van Hees)
23+
. Fixed bug #61759 (class_alias() should accept classes with leading
24+
backslashes). (Julien)
2125
. Fixed bug #61345 (CGI mode - make install don't work). (Michael Heimpold)
2226
. Cherry-picked some DTrace build commits (allowing builds on Linux,
2327
bug #62691, and bug #63706) from PHP 5.5 branch

Zend/tests/bug65579.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Bug #65579 (Using traits with get_class_methods causes segfault)
3+
--FILE--
4+
<?php
5+
trait ParentTrait {
6+
public function testMethod() { }
7+
}
8+
9+
trait ChildTrait {
10+
use ParentTrait {
11+
testMethod as testMethodFromParentTrait;
12+
}
13+
public function testMethod() { }
14+
}
15+
16+
class TestClass {
17+
use ChildTrait;
18+
}
19+
20+
$obj = new TestClass();
21+
var_dump(get_class_methods($obj));
22+
?>
23+
--EXPECT--
24+
array(2) {
25+
[0]=>
26+
string(10) "testMethod"
27+
[1]=>
28+
string(25) "testmethodfromparenttrait"
29+
}

Zend/zend_API.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,7 +2514,12 @@ ZEND_API int zend_register_class_alias_ex(const char *name, int name_len, zend_c
25142514
char *lcname = zend_str_tolower_dup(name, name_len);
25152515
int ret;
25162516

2517-
ret = zend_hash_add(CG(class_table), lcname, name_len+1, &ce, sizeof(zend_class_entry *), NULL);
2517+
if (lcname[0] == '\\') {
2518+
ret = zend_hash_add(CG(class_table), lcname+1, name_len, &ce, sizeof(zend_class_entry *), NULL);
2519+
} else {
2520+
ret = zend_hash_add(CG(class_table), lcname, name_len+1, &ce, sizeof(zend_class_entry *), NULL);
2521+
}
2522+
25182523
efree(lcname);
25192524
if (ret == SUCCESS) {
25202525
ce->refcount++;
@@ -3917,15 +3922,16 @@ ZEND_API const char* zend_find_alias_name(zend_class_entry *ce, const char *name
39173922
{
39183923
zend_trait_alias *alias, **alias_ptr;
39193924

3920-
alias_ptr = ce->trait_aliases;
3921-
alias = *alias_ptr;
3922-
while (alias) {
3923-
if (alias->alias_len == len &&
3924-
!strncasecmp(name, alias->alias, alias->alias_len)) {
3925-
return alias->alias;
3926-
}
3927-
alias_ptr++;
3925+
if ((alias_ptr = ce->trait_aliases)) {
39283926
alias = *alias_ptr;
3927+
while (alias) {
3928+
if (alias->alias_len == len &&
3929+
!strncasecmp(name, alias->alias, alias->alias_len)) {
3930+
return alias->alias;
3931+
}
3932+
alias_ptr++;
3933+
alias = *alias_ptr;
3934+
}
39293935
}
39303936

39313937
return name;

Zend/zend_builtin_functions.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,15 +1399,8 @@ ZEND_FUNCTION(class_alias)
13991399
return;
14001400
}
14011401

1402-
if (!autoload) {
1403-
lc_name = do_alloca(class_name_len + 1, use_heap);
1404-
zend_str_tolower_copy(lc_name, class_name, class_name_len);
1402+
found = zend_lookup_class_ex(class_name, class_name_len, NULL, autoload, &ce TSRMLS_CC);
14051403

1406-
found = zend_hash_find(EG(class_table), lc_name, class_name_len+1, (void **) &ce);
1407-
free_alloca(lc_name, use_heap);
1408-
} else {
1409-
found = zend_lookup_class(class_name, class_name_len, &ce TSRMLS_CC);
1410-
}
14111404
if (found == SUCCESS) {
14121405
if ((*ce)->type == ZEND_USER_CLASS) {
14131406
if (zend_register_class_alias_ex(alias_name, alias_name_len, *ce TSRMLS_CC) == SUCCESS) {

0 commit comments

Comments
 (0)