On 12 July 2020 11:24:50 BST, Manuel Canga <p...@manuelcanga.dev> wrote:
>4. Other option is creating a  new function( not yet available in PHP )
>like:
>
>```
>array_check_scheme( array $array, array $scheme,  bool $forced = false 
>): bool
>```


The problem with this, whether built in or not, is that you have to express 
everything with strings rather than keywords. That means, for instance, that 
invalid values in the definitions themselves will only error at run-time. The 
definitions also tend to get verbose pretty quickly.

To make it concise and checked at compile-time, you need it to be a construct 
that pairs identifiers to types without first representing them as strings, 
e.g. to write `?string $foo = 'hello'` rather than `'foo' => ['type'=>'string', 
'nullable'=>true, 'default'=>'hello']`. It turns out we already have a 
construct for doing that: function signatures.

If the input is an actual array or object coming from "outside", you're 
probably going to want a more extensible validation system anyway. Those are 
really hard to design, and probably best left to userland where people can 
choose the tradeoffs they prefer.

Regards,

-- 
Rowan Tommins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to