possible value. This value results in scandir() performing no sorting: on
local filesystems, this allows files to be returned in native filesystem
order.
+- stream_select() now preserves the keys of the passed array, be they numeric or
+ strings. This breaks code that iterated the resulting stream array using a
+ numeric index, but makes easier to identify which of the passed streams are
+ present in the result.
===================================
zend_hash_init(new_hash, zend_hash_num_elements(Z_ARRVAL_P(stream_array)), NULL, ZVAL_PTR_DTOR, 0);
for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(stream_array));
- zend_hash_get_current_data(Z_ARRVAL_P(stream_array), (void **) &elem) == SUCCESS;
+ zend_hash_has_more_elements(Z_ARRVAL_P(stream_array)) == SUCCESS;
zend_hash_move_forward(Z_ARRVAL_P(stream_array))) {
+ int type;
+ char *key;
+ uint key_len;
+ ulong num_ind;
+
+ type = zend_hash_get_current_key_ex(Z_ARRVAL_P(stream_array),
+ &key, &key_len, &num_ind, 0, NULL);
+ if (type == HASH_KEY_NON_EXISTANT ||
+ zend_hash_get_current_data(Z_ARRVAL_P(stream_array), (void **) &elem) == FAILURE) {
+ continue; /* should not happen */
+ }
+
php_stream_from_zval_no_verify(stream, elem);
if (stream == NULL) {
continue;
*/
if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&this_fd, 1) && this_fd >= 0) {
if (PHP_SAFE_FD_ISSET(this_fd, fds)) {
- zend_hash_next_index_insert(new_hash, (void *)elem, sizeof(zval *), (void **)&dest_elem);
+ if (type == HASH_KEY_IS_LONG) {
+ zend_hash_index_update(new_hash, num_ind, (void *)elem, sizeof(zval *), (void **)&dest_elem);
+ } else { /* HASH_KEY_IS_STRING */
+ zend_hash_update(new_hash, key, key_len, (void *)elem, sizeof(zval *), (void **)&dest_elem);
+ }
+
if (dest_elem) {
zval_add_ref(dest_elem);
}
--- /dev/null
+--TEST--
+Bug #53427 (stream_select does not preserve keys)
+--FILE--
+<?php
+$read[1] = fopen(__FILE__, "r");
+$read["myindex"] = reset($read);
+$write = NULL;
+$except = NULL;
+
+var_dump($read);
+
+stream_select($read, $write, $except, 0);
+
+var_dump($read);
+--EXPECTF--
+array(2) {
+ [1]=>
+ resource(%d) of type (stream)
+ ["myindex"]=>
+ resource(%d) of type (stream)
+}
+array(2) {
+ [1]=>
+ resource(%d) of type (stream)
+ ["myindex"]=>
+ resource(%d) of type (stream)
+}