I would like to create my first RFC proposing adding a new operator
`!instanceof` named `T_NOT_INSTANCEOF`.

The purpose of this RFC is to add syntactic sugar for checking if an object
is not an instance of something else.
The current syntax for checking not instance of looks the following way
```php
!$object instanceof MyClass
```
When I read this I read it as:
Negate the `$object` variable and check if that is an instance of `MyClass`.

My proposed operator would allow for the following syntax
```php
$object !instanceof MyClass
```
This is for me and people I have spoken to a much clearer syntax.


Some arguments on other ways the not instance of can currently be written
```php
!($object instanceof MyClass) // Wrapping in parenthesis
! $object instanceof MyClass // Simply adding spacing
```
My main problem with these alternative syntaxes is the readability when
added inside an `if` condition
```php
if(!($object instanceof MyClass)) { ...
if(! $object instanceof MyClass) { ...
```
compared to
```php
if($object !instanceof MyClass) { ...
```


In regards to implementing the feature, I wouldn't mind trying to do that
myself. I believe this change is relatively simple in the parser and AST
and something I should be able to figure out.


What do people think about this? Would love to clarify if needed.

Best regards
Oliver Nybroe (he/him)

Reply via email to