On 22.03.20, 18:17, "Dan Ackroyd" <dan...@basereality.com> wrote:

> $condition || throw new Exception('$condition must be truthy')
>   && $condition2 || throw new Exception('$condition2 must be truthy');
> 
> The "Deprecate left-associative ternary operator"* RFC made it so that
> parentheses are required when ternary operators are nested in
> complicated statements.
> 
> Would a similar requirement for parentheses around complicated throw
> expressions be a suitable solution to avoid people being surprised by
> the behaviour?

I've thought about this some more. There is a reasonable way to recognize this, 
namely to check if the expression after the throw keyword is of type 
ZEND_AST_OR or ZEND_AST_AND. The expression above will fail with this message 
(given that $condition is false):

```
Fatal error: Uncaught Error: Can only throw objects in ...
```

IMO this is clear enough that a message for this edge case is not necessary.

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

Reply via email to