sandrokeil / php-to-zephir

Convert PHP 7 files to Zephir zep files and create a native PHP extension
Other
28 stars 5 forks source link

Syntax #2

Open yejune opened 5 years ago

yejune commented 5 years ago

php

function foo(?array $t) {
}

converted zephir

function foo(?array t) {
}

right syntax

function foo(array! t) {
}
sandrokeil commented 5 years ago

Looking at the docs this would disable type check right? But we want only allow an array or null.

danhunsaker commented 5 years ago

array! forces the value to be an array; if anything else is passed, rather than coerce the value, an exception is thrown. array by itself doesn't force non-coercion, though as array isn't a scalar type, automatic coercion isn't generally supported anyway.

Ultimately, though, ?array means array|null in PHP, which Zephir supports via array t = null, rather than using a modifier.

sandrokeil commented 5 years ago

I guess we have to wait for Allow nullable parameter because ?array $t !== $t = null. You must provide an array or null and you can not leave it empty like with array $t = null.

So the workaround could be array t = null for zephir?