> To be honest I am kinda hot and cold about how close it is to the 
> ternary operator.  On the one hand the two could be easily confused, but 
> on the other hand they are in fact very similar in function in which 
> case we could "market" (meaning document) them as being related.
> 
> Ternary operator:
> 
> $a = $b ? $b : $c;
> 
> Compound Ternary operator:
> 
> $a = $b ?: $c;

Not that my opinion makes much difference, but from an
end-user/developer point of view, overloading ?: is not a
good idea:

  a) Every other language that uses ?: (and there are a fair number of
     them) gives it the same behavior: if/then/else.  Adding additional
     functionality to ?: would be entirely unexpected.

  b) Upon seeing this initially, my first guess at functionality:

       $a = $b ?: $c;

     My guess is that it would imply that $a is set to NULL or
     becomes undefined in the case that $b evaluates to true, and set to $c
     if $b evaluates to false.

     Note that this is completely different from what actually happens.
     In this instance, if I've not encountered the operator before,
     I'm more likely to assume that my guess at its functionality
     is correct.  However, if it's

       $a = function_name($b, $c);

     I'll immediately go to www.php.net/manual to look up
     'function_name'.

As far as introducing operators to PHP that have no equivalents in
other common languages: IMHO you'd need a very strong case to introduce
them for precisely the two reasons outlined above, most likely
some new programming paradigm that occurs often enough and
is similar enough in functionality to one of the current set of operators
to justify using an operator as a shortcut for it.

-Bob

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to