MCPcopy Index your code
hub / github.com/php/frankenphp / phpArray

Function phpArray

types.go:224–245  ·  view source on GitHub ↗
(entries map[string]T, order []string)

Source from the content-addressed store, hash-verified

222}
223
224func phpArray[T any](entries map[string]T, order []string) unsafe.Pointer {
225 var zendArray *C.zend_array
226
227 if len(order) != 0 {
228 zendArray = createNewArray((uint32)(len(order)))
229 for _, key := range order {
230 val := entries[key]
231 zval := phpValue(val)
232 C.zend_hash_str_update(zendArray, toUnsafeChar(key), C.size_t(len(key)), zval)
233 C.__efree__(unsafe.Pointer(zval))
234 }
235 } else {
236 zendArray = createNewArray((uint32)(len(entries)))
237 for key, val := range entries {
238 zval := phpValue(val)
239 C.zend_hash_str_update(zendArray, toUnsafeChar(key), C.size_t(len(key)), zval)
240 C.__efree__(unsafe.Pointer(zval))
241 }
242 }
243
244 return unsafe.Pointer(zendArray)
245}
246
247// EXPERIMENTAL: PHPPackedArray converts a Go slice to a PHP zval with a zend_array value.
248func PHPPackedArray[T any](slice []T) unsafe.Pointer {

Callers

nothing calls this directly

Calls 3

createNewArrayFunction · 0.85
phpValueFunction · 0.85
toUnsafeCharFunction · 0.85

Tested by

no test coverage detected