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

Function phpValue

types.go:375–413  ·  view source on GitHub ↗
(value any)

Source from the content-addressed store, hash-verified

373}
374
375func phpValue(value any) *C.zval {
376 zval := (*C.zval)(C.__emalloc__(C.size_t(unsafe.Sizeof(C.zval{}))))
377
378 if toZvalObj, ok := value.(toZval); ok {
379 toZvalObj.toZval(zval)
380 return zval
381 }
382
383 switch v := value.(type) {
384 case nil:
385 C.__zval_null__(zval)
386 case bool:
387 C.__zval_bool__(zval, C._Bool(v))
388 case int:
389 C.__zval_long__(zval, C.zend_long(v))
390 case int64:
391 C.__zval_long__(zval, C.zend_long(v))
392 case float64:
393 C.__zval_double__(zval, C.double(v))
394 case string:
395 if v == "" {
396 C.__zval_empty_string__(zval)
397 break
398 }
399 str := (*C.zend_string)(PHPString(v, false))
400 C.__zval_string__(zval, str)
401 case AssociativeArray[any]:
402 C.__zval_arr__(zval, (*C.zend_array)(PHPAssociativeArray[any](v)))
403 case map[string]any:
404 C.__zval_arr__(zval, (*C.zend_array)(PHPMap[any](v)))
405 case []any:
406 C.__zval_arr__(zval, (*C.zend_array)(PHPPackedArray[any](v)))
407 default:
408 C.__efree__(unsafe.Pointer(zval))
409 panic(fmt.Sprintf("unsupported Go type %T", v))
410 }
411
412 return zval
413}
414
415// createNewArray creates a new zend_array with the specified size.
416func createNewArray(size uint32) *C.zend_array {

Callers 4

phpArrayFunction · 0.85
PHPPackedArrayFunction · 0.85
PHPValueFunction · 0.85
CallPHPCallableFunction · 0.85

Calls 2

PHPStringFunction · 0.85
toZvalMethod · 0.65

Tested by

no test coverage detected