Is there any library for refined types in php that can allow me to do something like this?
function getAge(int positive $age){
...
}
getAge(-1) // error -1 < 0
Thanks!
Is there any library for refined types in php that can allow me to do something like this?
function getAge(int positive $age){
...
}
getAge(-1) // error -1 < 0
Thanks!
Copyright © 2021 Jogjafile Inc.
You would need to implement Refinement-Types at the engine level. No one did this yet.
Or use a userland Preprocessor, like http://github.com/marcioAlmada/yay.
Or implement the refined types as Value Objects, e.g.
However, this means the int is no longer a scalar and cannot be used in the same way as you'd use a scalar, e.g. all operations would need to be methods. You won't be able to do
$age++
anymore.