Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/types/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,11 @@ impl<'a> Iter<'a> {
)
};

if key_type == -1 {
// Key type `-1` is ???
// Key type `1` is string
// Key type `2` is long
// Key type `3` is null meaning the end of the array
if key_type == -1 || key_type == 3 {
return None;
}

Expand All @@ -753,10 +757,16 @@ impl<'a> Iter<'a> {
);
}
let value = unsafe {
&*zend_hash_get_current_data_ex(
let val_ptr = zend_hash_get_current_data_ex(
self.ht as *const ZendHashTable as *mut ZendHashTable,
&mut self.pos as *mut HashPosition,
)
);

if val_ptr.is_null() {
return None;
}

&*val_ptr
};

if !key.is_long() && !key.is_string() {
Expand Down
5 changes: 3 additions & 2 deletions tests/src/integration/array.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
require('_utils.php');

// Tests sequential arrays
$array = test_array(['a', 'b', 'c']);
$array = test_array(['a', 'b', 'c', 'd']);
unset($array[2]);

assert(is_array($array));
assert(count($array) === 3);
assert(in_array('a', $array));
assert(in_array('b', $array));
assert(in_array('c', $array));
assert(in_array('d', $array));

// Tests associative arrays
$assoc = test_array_assoc([
Expand Down
2 changes: 1 addition & 1 deletion tests/src/integration/array.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[test]
fn binary_works() {
fn array_works() {
assert!(crate::integration::run_php("array.php"));
}