Skip to content

Commit 7fca07e

Browse files
feat(types): expose IsPacked to help dealing with hashmaps and lists in Go code
1 parent 3599299 commit 7fca07e

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

docs/extensions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +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 *C.zend_array) bool` - Check if a PHP array is packed (indexed only) or associative (key-value pairs)
215216

216217
### Working with Callables
217218

docs/fr/extensions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ func process_data_packed(arr *C.zval) unsafe.Pointer {
209209
- `frankenphp.GoAssociativeArray(arr unsafe.Pointer, ordered bool) frankenphp.AssociativeArray` - Convertir un tableau PHP vers un `AssociativeArray` Go ordonné (map avec ordre)
210210
- `frankenphp.GoMap(arr unsafe.Pointer) map[string]any` - Convertir un tableau PHP vers une map Go non ordonnée
211211
- `frankenphp.GoPackedArray(arr unsafe.Pointer) []any` - Convertir un tableau PHP vers un slice Go
212+
- `frankenphp.IsPacked(zval *C.zend_array) bool` - Vérifie si le tableau PHP est une liste ou un tableau associatif
212213

213214
### Travailler avec des Callables
214215

types.go

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

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 {
423+
return false
424+
}
425+
426+
return htIsPacked((*C.zend_array)(arr))
427+
}
428+
419429
// htIsPacked checks if a zend_array is a list (packed) or hashmap (not packed).
420430
func htIsPacked(ht *C.zend_array) bool {
421431
flags := *(*C.uint32_t)(unsafe.Pointer(&ht.u[0]))

0 commit comments

Comments
 (0)