php-to-zephir icon indicating copy to clipboard operation
php-to-zephir copied to clipboard

Syntax

Open yejune opened this issue 6 years ago • 3 comments

php

function foo(?array $t) {
}

converted zephir

function foo(?array t) {
}

right syntax

function foo(array! t) {
}

yejune avatar Jan 09 '19 17:01 yejune

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

sandrokeil avatar Jan 09 '19 18:01 sandrokeil

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.

danhunsaker avatar Jan 09 '19 23:01 danhunsaker

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?

sandrokeil avatar Jan 10 '19 16:01 sandrokeil