EXPERIMENTAL: PHPString converts a Go string to a zend_string with copy. The string can be non-persistent (automatically freed after the request by the ZMM) or persistent. If you choose the second mode, it is your repsonsability to free the allocated memory.
(s string, persistent bool)
| 47 | // non-persistent (automatically freed after the request by the ZMM) or persistent. If you choose |
| 48 | // the second mode, it is your repsonsability to free the allocated memory. |
| 49 | func PHPString(s string, persistent bool) unsafe.Pointer { |
| 50 | if s == "" { |
| 51 | return nil |
| 52 | } |
| 53 | |
| 54 | zendStr := C.zend_string_init( |
| 55 | (*C.char)(unsafe.Pointer(unsafe.StringData(s))), |
| 56 | C.size_t(len(s)), |
| 57 | C._Bool(persistent), |
| 58 | ) |
| 59 | |
| 60 | return unsafe.Pointer(zendStr) |
| 61 | } |
| 62 | |
| 63 | // AssociativeArray represents a PHP array with ordered key-value pairs |
| 64 | type AssociativeArray[T any] struct { |
no outgoing calls