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

Function CallPHPCallable

types.go:478–527  ·  view source on GitHub ↗

EXPERIMENTAL: CallPHPCallable executes a PHP callable with the given parameters. Returns the result of the callable as a Go interface{}, or nil if the call failed.

(cb unsafe.Pointer, params []interface{})

Source from the content-addressed store, hash-verified

476// EXPERIMENTAL: CallPHPCallable executes a PHP callable with the given parameters.
477// Returns the result of the callable as a Go interface{}, or nil if the call failed.
478func CallPHPCallable(cb unsafe.Pointer, params []interface{}) interface{} {
479 if cb == nil {
480 return nil
481 }
482
483 callback := (*C.zval)(cb)
484 if callback == nil {
485 return nil
486 }
487
488 if C.__zend_is_callable__(callback) == 0 {
489 return nil
490 }
491
492 paramCount := len(params)
493 var paramStorage *C.zval
494 if paramCount > 0 {
495 paramStorage = (*C.zval)(C.__emalloc__(C.size_t(paramCount) * C.size_t(unsafe.Sizeof(C.zval{}))))
496 defer func() {
497 for i := 0; i < paramCount; i++ {
498 targetZval := (*C.zval)(unsafe.Pointer(uintptr(unsafe.Pointer(paramStorage)) + uintptr(i)*unsafe.Sizeof(C.zval{})))
499 C.zval_ptr_dtor(targetZval)
500 }
501 C.__efree__(unsafe.Pointer(paramStorage))
502 }()
503
504 for i, param := range params {
505 targetZval := (*C.zval)(unsafe.Pointer(uintptr(unsafe.Pointer(paramStorage)) + uintptr(i)*unsafe.Sizeof(C.zval{})))
506 sourceZval := phpValue(param)
507 *targetZval = *sourceZval
508 C.__efree__(unsafe.Pointer(sourceZval))
509 }
510 }
511
512 var retval C.zval
513
514 result := C.__call_user_function__(callback, &retval, C.uint32_t(paramCount), paramStorage)
515 if result != C.SUCCESS {
516 return nil
517 }
518
519 goResult, err := goValue[any](&retval)
520 C.zval_ptr_dtor(&retval)
521
522 if err != nil {
523 return nil
524 }
525
526 return goResult
527}

Callers 3

my_array_mapFunction · 0.92
my_filterFunction · 0.92
TransformMethod · 0.92

Calls 1

phpValueFunction · 0.85

Tested by

no test coverage detected