zephir
zephir copied to clipboard
Add ability to assign default value using the fetch operator.
I'm thinking that it would be nice to be able to assign default values for perhaps just some simple values (no object instantiations) using the fetch operator.
So this real Phalcon code from the PDO class could be simplified.
if fetch options, descriptor["options"] {
unset descriptor["options"];
} else {
let options = [];
}
into this:
if fetch options = [], descriptor["options"] {
unset descriptor["options"];
}
I'm thinking that perhaps it would be best to keep it to be able to only set it with; an empty array, number, boolean or string. That would do a lot.
So real life code example above I needed to unset a key, but that is no terrible common. I'd love to see the following someday (notice no conditional):
fetch options = [], descriptor["options"];
It would need to be evaluated whether not checking types is correct but in many cases it can be fine. That one line is doing a lot of boiler plate that it would be great not to have to see. Its easy to scan once you know how the operator works.