Skip to content

Commit fb15e9c

Browse files
Simplify IsPacked
1 parent f5be7ab commit fb15e9c

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

docs/extensions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func process_data_packed(arr *C.zend_array) unsafe.Pointer {
212212
- `frankenphp.GoAssociativeArray(arr unsafe.Pointer, ordered bool) frankenphp.AssociativeArray` - Convert a PHP array to an ordered Go `AssociativeArray` (map with order)
213213
- `frankenphp.GoMap(arr unsafe.Pointer) map[string]any` - Convert a PHP array to an unordered Go map
214214
- `frankenphp.GoPackedArray(arr unsafe.Pointer) []any` - Convert a PHP array to a Go slice
215-
- `frankenphp.IsPacked(zval unsafe.Pointer) bool` - Check if a PHP array is packed (indexed only) or associative (key-value pairs)
215+
- `frankenphp.IsPacked(zval *C.zend_array) bool` - Check if a PHP array is packed (indexed only) or associative (key-value pairs)
216216

217217
### Working with Callables
218218

types.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -416,24 +416,14 @@ func createNewArray(size uint32) *C.zend_array {
416416
return (*C.zend_array)(unsafe.Pointer(arr))
417417
}
418418

419-
// IsPacked determines if the given zval pointer represents a packed array (list).
420-
// Returns false if the zval is nil, not an array, or not packed.
421-
func IsPacked(zval unsafe.Pointer) bool {
422-
if zval == nil {
423-
return false
424-
}
425-
426-
v, err := extractZvalValue((*C.zval)(zval), C.IS_ARRAY)
427-
if err != nil {
428-
return false
429-
}
430-
431-
ht := (*C.HashTable)(v)
432-
if ht == nil {
419+
// IsPacked determines if the given zend_array is a packed array (list).
420+
// Returns false if the array is nil or not packed.
421+
func IsPacked(arr unsafe.Pointer) bool {
422+
if arr == nil {
433423
return false
434424
}
435425

436-
return htIsPacked(ht)
426+
return htIsPacked((*C.zend_array)(arr))
437427
}
438428

439429
// htIsPacked checks if a zend_array is a list (packed) or hashmap (not packed).

0 commit comments

Comments
 (0)