Re: [RFC] Allow ::class on objects
| From: | Guilliam Xavier | Date: | Fri, 10 Jan 2020 14:26:15 +0000 |
| Subject: | Re: [RFC] Allow ::class on objects | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-108089@lists.php.net to get a copy of this message | ||
Hi,
On Thu, Jan 9, 2020 at 10:02 PM Kalle Sommer Nielsen <kalle@php.net> wrote:
>
> [...]
>
> use Interfaces;
> if(!$object instanceof Interfaces\MyInterface)
> {
> // Notice the ! is right associative and instanceof is non
> associative, hence the lack of parantheses
> }
Sorry for off-topic but that comment is incorrect: the fact that
!$x instanceof Foo is evaluated as
!($x instanceof Foo) (which I find more readable with explicit
parentheses, by the way) is not due to the *associativity* of the
operators but to their relative *precedence*.
For instance, === is non-associative too but
!$x === 42 is evaluated as
(!$x) === 42 (not as !($x === 42)).
According to the docs, associativity only matters for operators of
equal precedence, e.g.
4 - 3 - 2 is evaluated as
(4 - 3) - 2,
and
4 ** 3 ** 2 is evaluated as
4 ** (3 ** 2).
--
Guilliam Xavier