Skip to content

Commit 960d5be

Browse files
committed
Merge branch 'PHP-5.4' into PHP-5.5
* PHP-5.4: Partial fix for bug #64239
2 parents 74e11fb + 984561c commit 960d5be

File tree

2 files changed

+46
-13
lines changed

2 files changed

+46
-13
lines changed

Zend/tests/bug64239_1.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #64239 (get_class_methods() changed behavior)
3+
--FILE--
4+
<?php
5+
class A {
6+
public function test() { $this->backtrace(); }
7+
}
8+
class B {
9+
use T2 { t2method as Bmethod; }
10+
}
11+
trait T2 {
12+
public function t2method() {
13+
}
14+
}
15+
var_dump(get_class_methods("B"));
16+
--EXPECT--
17+
array(2) {
18+
[0]=>
19+
string(7) "bmethod"
20+
[1]=>
21+
string(8) "t2method"
22+
}

Zend/zend_builtin_functions.c

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,13 @@ ZEND_FUNCTION(get_object_vars)
10251025
}
10261026
/* }}} */
10271027

1028+
static int same_name(const char *key, const char *name, zend_uint name_len)
1029+
{
1030+
char *lcname = zend_str_tolower_dup(name, name_len);
1031+
int ret = memcmp(lcname, key, name_len) == 0;
1032+
efree(lcname);
1033+
return ret;
1034+
}
10281035

10291036
/* {{{ proto array get_class_methods(mixed class)
10301037
Returns an array of method names for class or class instance. */
@@ -1072,14 +1079,26 @@ ZEND_FUNCTION(get_class_methods)
10721079
uint len = strlen(mptr->common.function_name);
10731080

10741081
/* Do not display old-style inherited constructors */
1075-
if ((mptr->common.fn_flags & ZEND_ACC_CTOR) == 0 ||
1076-
mptr->common.scope == ce ||
1077-
zend_hash_get_current_key_ex(&ce->function_table, &key, &key_len, &num_index, 0, &pos) != HASH_KEY_IS_STRING ||
1078-
zend_binary_strcasecmp(key, key_len-1, mptr->common.function_name, len) == 0) {
1079-
1082+
if (zend_hash_get_current_key_ex(&ce->function_table, &key, &key_len, &num_index, 0, &pos) != HASH_KEY_IS_STRING) {
10801083
MAKE_STD_ZVAL(method_name);
10811084
ZVAL_STRINGL(method_name, mptr->common.function_name, len, 1);
10821085
zend_hash_next_index_insert(return_value->value.ht, &method_name, sizeof(zval *), NULL);
1086+
} else if ((mptr->common.fn_flags & ZEND_ACC_CTOR) == 0 ||
1087+
mptr->common.scope == ce ||
1088+
zend_binary_strcasecmp(key, key_len-1, mptr->common.function_name, len) == 0) {
1089+
1090+
if (mptr->type == ZEND_USER_FUNCTION &&
1091+
*mptr->op_array.refcount > 1 &&
1092+
(len != key_len - 1 ||
1093+
!same_name(key, mptr->common.function_name, len))) {
1094+
MAKE_STD_ZVAL(method_name);
1095+
ZVAL_STRINGL(method_name, key, key_len - 1, 1);
1096+
zend_hash_next_index_insert(return_value->value.ht, &method_name, sizeof(zval *), NULL);
1097+
} else {
1098+
MAKE_STD_ZVAL(method_name);
1099+
ZVAL_STRINGL(method_name, mptr->common.function_name, len, 1);
1100+
zend_hash_next_index_insert(return_value->value.ht, &method_name, sizeof(zval *), NULL);
1101+
}
10831102
}
10841103
}
10851104
zend_hash_move_forward_ex(&ce->function_table, &pos);
@@ -1625,14 +1644,6 @@ ZEND_FUNCTION(restore_exception_handler)
16251644
}
16261645
/* }}} */
16271646

1628-
static int same_name(const char *key, const char *name, zend_uint name_len)
1629-
{
1630-
char *lcname = zend_str_tolower_dup(name, name_len);
1631-
int ret = memcmp(lcname, key, name_len) == 0;
1632-
efree(lcname);
1633-
return ret;
1634-
}
1635-
16361647
static int copy_class_or_interface_name(zend_class_entry **pce TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
16371648
{
16381649
zval *array = va_arg(args, zval *);

0 commit comments

Comments
 (0)