Skip to content

Commit

Permalink
fix: Remove PHP 8.0 syntax to maintain PHP 7.4 compatibility (#19)
Browse files Browse the repository at this point in the history
Union return types are not supported in PHP 7.4. Thankfully, `T|null` is
equivalent to `?T`. See below:

https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.nullable
  • Loading branch information
oatmael authored Jul 3, 2024
1 parent 09c4227 commit 6ab7293
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/LibExtism.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function extism_current_plugin_memory_length(FFI\CData $plugin, int $offset): in
return $this->ffi->extism_current_plugin_memory_length($plugin, $offset);
}

function extism_plugin_new(string $wasm, int $wasm_size, FFI\CData $functions, int $n_functions, bool $with_wasi, ?FFI\CData $errmsg): FFI\CData|null
function extism_plugin_new(string $wasm, int $wasm_size, FFI\CData $functions, int $n_functions, bool $with_wasi, ?FFI\CData $errmsg): ?FFI\CData
{
$ptr = $this->owned("uint8_t", $wasm);
$wasi = $with_wasi ? 1 : 0;
Expand Down Expand Up @@ -154,7 +154,7 @@ function extism_function_set_namespace(FFI\CData $handle, string $name)
$this->ffi->extism_function_set_namespace($handle, $namePtr);
}

function toCArray(array $array, string $type): FFI\CData | null
function toCArray(array $array, string $type): ?FFI\CData
{
if (count($array) == 0) {
return $this->ffi->new($type . "*");
Expand All @@ -168,7 +168,7 @@ function toCArray(array $array, string $type): FFI\CData | null
return $cArray;
}

function owned(string $type, string $string): FFI\CData|null
function owned(string $type, string $string): ?FFI\CData
{
if (strlen($string) == 0) {
return null;
Expand All @@ -179,7 +179,7 @@ function owned(string $type, string $string): FFI\CData|null
return $str;
}

function ownedZero(string $string): FFI\CData|null
function ownedZero(string $string): ?FFI\CData
{
return $this->owned("char", "$string\0");
}
Expand All @@ -189,4 +189,4 @@ function startsWith($haystack, $needle) {
}
}

?>
?>

0 comments on commit 6ab7293

Please sign in to comment.