1
0
mirror of https://github.com/php/php-src.git synced 2026-04-09 00:53:30 +02:00

Merge branch 'PHP-7.3' into PHP-7.4

This commit is contained in:
Nikita Popov
2019-04-08 13:00:20 +02:00
2 changed files with 43 additions and 4 deletions

View File

@@ -694,13 +694,15 @@ static int stream_array_emulate_read_fd_set(zval *stream_array)
HashTable *ht;
php_stream *stream;
int ret = 0;
zend_ulong num_ind;
zend_string *key;
if (Z_TYPE_P(stream_array) != IS_ARRAY) {
return 0;
}
ht = zend_new_array(zend_hash_num_elements(Z_ARRVAL_P(stream_array)));
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(stream_array), elem) {
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(stream_array), num_ind, key, elem) {
ZVAL_DEREF(elem);
php_stream_from_zval_no_verify(stream, elem);
if (stream == NULL) {
@@ -713,10 +715,12 @@ static int stream_array_emulate_read_fd_set(zval *stream_array)
* This branch of code also allows blocking streams with buffered data to
* operate correctly in stream_select.
* */
dest_elem = zend_hash_next_index_insert(ht, elem);
if (dest_elem) {
zval_add_ref(dest_elem);
if (!key) {
dest_elem = zend_hash_index_update(ht, num_ind, elem);
} else {
dest_elem = zend_hash_update(ht, key, elem);
}
zval_add_ref(dest_elem);
ret++;
continue;
}

View File

@@ -0,0 +1,35 @@
--TEST--
Bug #53427 + emulate_read (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);
fread(reset($read), 1);
stream_select($read, $write, $except, 0); // // emulate_read
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)
}
array(2) {
[1]=>
resource(%d) of type (stream)
["myindex"]=>
resource(%d) of type (stream)
}