zephir
zephir copied to clipboard
Add abiilty to check for types using the fetch operator
Currently we can do the following:
if fetch blah, options["blah"] {
}
I'm thinking that it would be great to be able to type the fetch like this:
if fetch string blah, options["blah"] {
}
if fetch <Blah> blah, options["blah"] {
}
If more fine grained control was needed then just don't use the types. Sometimes I won't want to check the existence first to throw an exception, then if it doesn't exist and then another check with exception if the type doesn't match. However sometimes I don't care that much and would like to do it with less code (less information).
Like this?
if fetch blah, options["blah"] {
if typeof blah == 'string' {
// ...
}
}
Of course it can be done without new language features.
It more looks like a pattern matching
Already mentioned in discord - isbool isstring etc macros also can be added.
if isset X && typeof X === T
currently using a lot of in param check.