Skip to content

Commit 28801bf

Browse files
committed
Respect property visibility in array_column
1 parent c0d8dc5 commit 28801bf

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

ext/standard/array.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3521,18 +3521,17 @@ static inline zval *array_column_fetch_prop(zval *data, zval *name, zval *rv)
35213521
zval *prop = NULL;
35223522

35233523
if (Z_TYPE_P(data) == IS_OBJECT) {
3524-
zend_string *key = zval_get_string(name);
3524+
if (!Z_OBJ_HANDLER_P(data, has_property) || !Z_OBJ_HANDLER_P(data, read_property)) {
3525+
return NULL;
3526+
}
35253527

35263528
/* The has_property check is first performed in "exists" mode (which returns true for
35273529
* properties that are null but exist) and then in "has" mode to handle objects that
35283530
* implement __isset (which is not called in "exists" mode). */
3529-
if (!Z_OBJ_HANDLER_P(data, has_property)
3530-
|| Z_OBJ_HANDLER_P(data, has_property)(data, name, 2, NULL)
3531+
if (Z_OBJ_HANDLER_P(data, has_property)(data, name, 2, NULL)
35313532
|| Z_OBJ_HANDLER_P(data, has_property)(data, name, 0, NULL)) {
3532-
prop = zend_read_property(Z_OBJCE_P(data), data, ZSTR_VAL(key), ZSTR_LEN(key), 1, rv);
3533+
prop = Z_OBJ_HANDLER_P(data, read_property)(data, name, BP_VAR_R, NULL, rv);
35333534
}
3534-
3535-
zend_string_release(key);
35363535
} else if (Z_TYPE_P(data) == IS_ARRAY) {
35373536
if (Z_TYPE_P(name) == IS_STRING) {
35383537
prop = zend_hash_find(Z_ARRVAL_P(data), Z_STR_P(name));
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
array_column() respects property visibility
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
private $prop;
8+
public function __construct($value) {
9+
$this->prop = $value;
10+
}
11+
public function __isset($name) {
12+
return true;
13+
}
14+
public function __get($name) {
15+
return "__get($this->prop)";
16+
}
17+
}
18+
19+
$arr = [new Test("foobar")];
20+
var_dump(array_column($arr, "prop"));
21+
22+
?>
23+
--EXPECT--
24+
array(1) {
25+
[0]=>
26+
string(13) "__get(foobar)"
27+
}

0 commit comments

Comments
 (0)