On Wed, Feb 24, 2021 at 11:35 AM Mike Schinkel <m...@newclarity.net> wrote:

>
> On Feb 24, 2021, at 11:27 AM, Chase Peeler <chasepee...@gmail.com> wrote:
>
> On Tue, Feb 23, 2021 at 11:27 PM Mike Schinkel <m...@newclarity.net>
> wrote:
>
>> > On Feb 23, 2021, at 2:05 PM, Rowan Tommins <rowan.coll...@gmail.com>
>> wrote:
>> >
>> > On 23/02/2021 18:41, Albert Casademont wrote:
>> >> Sure, it's not a big deal having to write the ": null" but it doesn't
>> add
>> >> any value
>> >
>> >
>> > On the contrary, it adds an important piece of information: that the
>> default value is "null", rather than "false", or "0", or "new EmptyValue()".
>> > For instance, it doesn't seem at all obvious to me that this code
>> should produce a null:
>> >
>> > $items = [];
>> > $itemCount = $items ? count($items);
>> >
>> > I might be more convinced that "null" is the "natural" value if the
>> left-hand operand was only checked against null, not "falsiness": in that
>> case, you can read it as "if it's null, leave it alone". I'd still be
>> inclined towards "too specific to use up more syntax", though.
>>
>> If you look at it from a software engineering perspective — which is how
>> I assume most on this thread have been looking at it — being more explicit
>> in the code is probably a better practice than saving a few keystrokes.
>>
>> OTOH, if you view it from the perspective of a *templating* language —
>> which is what PHP was initially created to be, for the web — then the
>> reduction in visual noise from omitting ": null" would be a nice plus. And
>> in the case of templating, the distinction between null vs. false vs. ""
>> would be completely moot.
>>
>>
> But PHP isn't just a templating language anymore.
>
>
> It is not?  If it is not I think a lot of userland PHP developers never
> got that decree.
>
>
I didn't say it COULDN'T be used for templating (although even then I'd
suggest utilizing a library like smarty or twig) but that it is a lot more
than that. I'd also say that, good or bad, the direction of the language in
the last 15+ years has been to make it a robust language that can be used
for more than just templating.

> If PHP currently had support for omitting the third argument on the
> ternary operator, then I'd be against changes that required it given the BC
> implications.
>
>
> Can you elaborate on those?
>
>
Well it's pretty obvious. If php currently supported a statement like
"$user ? 'online'" then a change that requires the third argument would
break every single instance of code that didn't have one and wouldn't
provide any functional gains as nothing prevents people from adding on the
": null" if they want to. It's a moot point, though, because PHP doesn't
support it. I just included that statement to give context to my views  -
that I'm not automatically in favor of changes just because they enforce
better development practices.


> I think just dropping the need for a third argument on the existing
> ternary operator is a bad idea.
>
> I'm ambivalent when it comes to creating a new symbol to support this
> behavior (e.g. ?!). I don't really think it's necessary, but, I don't think
> it hurts anything either.
>
>
>
>> 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>
>>
>> Although one  ":null" eliminated is not that significant, PHP templates
>> for generating HTML are notorious for having conditionals littered
>> throughout, with tens if not hundreds of cases per file.  So being able to
>> drop the ":null" would be a really nice addition for templating.
>>
>> To emphasize this feature address templating use-cases one might argue
>> that dropping the "or" case of the trinary might only be supported when
>> between single-line "<?php" and "?>" delimiters.
>>
>> -Mike
>>
>> P.S. Of course making it work differently between single-line delimiters
>> and elsewhere would create inconsistency in the language so I probably
>> would not actually argue that, I was just trying to make a rhetorical point.
>>
>> --
>> PHP Internals - PHP Runtime Development Mailing List
>> To unsubscribe, visit: https://www.php.net/unsub.php
>>
>>
>
> --
> Chase Peeler
> chasepee...@gmail.com
>
>
>

-- 
Chase Peeler
chasepee...@gmail.com

Reply via email to