On 24/02/2021 04:26, Mike Schinkel wrote:
Repeating code similar to that from the message sent by David Rodrigues you can see that
eliminating the ": null" is less noisy:
<div class="user <?php user ? 'online' : null ?>">...</div>
<div class="user <?php user ? 'online' ?>">...</div>
That's an interesting use case. Of course, the logical default there is
actually '' (empty string) rather than null, since "echo null;" doesn't
actually make much sense, but null works under current type juggling rules.
Then again, perhaps this is a good example of why PHP *isn't* the best
choice any more if you want a templating language. Twig, for instance,
has exactly this facility
[https://twig.symfony.com/doc/3.x/templates.html#other-operators]:
{{ foo ? 'yes' : 'no' }}
{{ foo ?: 'no' }}is the same as {{ foo ? foo : 'no' }}
{{ foo ? 'yes' }}is the same as {{ foo ? 'yes' : '' }}
If we wanted to close the gap between Twig and plain PHP for templating,
this might be somewhere on the list, but after more significant features
like automatic escaping, filter / pipe syntax, etc.
Regards,
--
Rowan Tommins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php