$boolean = (boolean) $mixed;
But what about this radically shorter alternative?
$boolean = !!$mixed;
Both rely on the typecasting features of the underlying language, but the latter does the job in with two characters, while the former takes six or more.
Is this second construct strange to you? Not to me, not anymore. I find it spare and quite quite clear, but perhaps I’m just used to it after using it so long I can’t even remember where I first saw it (or whether I possibly even invented discovered it on my own).
What other quirky coding do you find delightful… or infuriating?