instead of true/false, I use numbers, which can be cast to bool
(bool)"1" //true
(bool)"0" //false
$cascade = (bool)Request::get('cascade', '1');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I must have done this a million times but today it's started to bother me.
Is there a more elegant way to accomplish this. Casting to boolean clearly doesn't work because a non empty string is true.
$cascade = Request::get('cascade', 'true');
$cascade = $cascade == 'true' ? true : false;
Another thing you could do is just not include the cascade param if the option is false, only add it if it's true. Then you could just see if the request has it.
$cascade = Request::has('cascade'); // true/false
Please or to participate in this conversation.