]> granicus.if.org Git - php/commitdiff
Use symtable lookup for arrays in array_column
authorNikita Popov <nikic@php.net>
Sat, 16 Apr 2016 07:56:08 +0000 (09:56 +0200)
committerNikita Popov <nikic@php.net>
Sat, 16 Apr 2016 07:59:01 +0000 (09:59 +0200)
ext/standard/array.c
ext/standard/tests/array/array_column_numeric_string_key.phpt [new file with mode: 0644]

index 61723e584f6f5210aadf9bf8f241d89c42f871b2..34dac68d1f9a65460964d6a3cac83887d37d368b 100644 (file)
@@ -3534,7 +3534,7 @@ static inline zval *array_column_fetch_prop(zval *data, zval *name, zval *rv)
                }
        } else if (Z_TYPE_P(data) == IS_ARRAY) {
                if (Z_TYPE_P(name) == IS_STRING) {
-                       prop = zend_hash_find(Z_ARRVAL_P(data), Z_STR_P(name));
+                       prop = zend_symtable_find(Z_ARRVAL_P(data), Z_STR_P(name));
                } else if (Z_TYPE_P(name) == IS_LONG) {
                        prop = zend_hash_index_find(Z_ARRVAL_P(data), Z_LVAL_P(name));
                }
diff --git a/ext/standard/tests/array/array_column_numeric_string_key.phpt b/ext/standard/tests/array/array_column_numeric_string_key.phpt
new file mode 100644 (file)
index 0000000..aed3c35
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+array_column() treats numeric string keys as usual
+--FILE--
+<?php
+
+$array = [[42 => 'a'], [42 => 'b']];
+var_dump(array_column($array, 42));
+var_dump(array_column($array, "42"));
+
+?>
+--EXPECT--
+array(2) {
+  [0]=>
+  string(1) "a"
+  [1]=>
+  string(1) "b"
+}
+array(2) {
+  [0]=>
+  string(1) "a"
+  [1]=>
+  string(1) "b"
+}