Skip to content

Commit c0d8dc5

Browse files
committed
Fixed bug #72031
1 parent 7e01c51 commit c0d8dc5

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ PHP NEWS
2323
- SQLite3:
2424
. Fixed bug #68849 (bindValue is not using the right data type). (Anatol)
2525

26+
- Standard:
27+
. Fixed bug #72031 (array_column() against an array of objects discards all
28+
values matching null). (Nikita)
29+
2630
28 Apr 2016 PHP 7.0.6
2731

2832
- Core:

ext/standard/array.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3523,9 +3523,15 @@ static inline zval *array_column_fetch_prop(zval *data, zval *name, zval *rv)
35233523
if (Z_TYPE_P(data) == IS_OBJECT) {
35243524
zend_string *key = zval_get_string(name);
35253525

3526-
if (!Z_OBJ_HANDLER_P(data, has_property) || Z_OBJ_HANDLER_P(data, has_property)(data, name, 1, NULL)) {
3526+
/* The has_property check is first performed in "exists" mode (which returns true for
3527+
* properties that are null but exist) and then in "has" mode to handle objects that
3528+
* 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+
|| Z_OBJ_HANDLER_P(data, has_property)(data, name, 0, NULL)) {
35273532
prop = zend_read_property(Z_OBJCE_P(data), data, ZSTR_VAL(key), ZSTR_LEN(key), 1, rv);
35283533
}
3534+
35293535
zend_string_release(key);
35303536
} else if (Z_TYPE_P(data) == IS_ARRAY) {
35313537
if (Z_TYPE_P(name) == IS_STRING) {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
--TEST--
2+
Bug #72031: array_column() against an array of objects discards all values matching null
3+
--FILE--
4+
<?php
5+
6+
class myObj {
7+
public $prop;
8+
public function __construct($prop) {
9+
$this->prop = $prop;
10+
}
11+
}
12+
13+
$objects = [
14+
new myObj(-1),
15+
new myObj(0),
16+
new myObj(1),
17+
new myObj(2),
18+
new myObj(null),
19+
new myObj(true),
20+
new myObj(false),
21+
new myObj('abc'),
22+
new myObj(''),
23+
];
24+
25+
var_dump(array_column($objects, 'prop'));
26+
27+
?>
28+
--EXPECT--
29+
array(9) {
30+
[0]=>
31+
int(-1)
32+
[1]=>
33+
int(0)
34+
[2]=>
35+
int(1)
36+
[3]=>
37+
int(2)
38+
[4]=>
39+
NULL
40+
[5]=>
41+
bool(true)
42+
[6]=>
43+
bool(false)
44+
[7]=>
45+
string(3) "abc"
46+
[8]=>
47+
string(0) ""
48+
}

0 commit comments

Comments
 (0)