Heya, While I definitely agree with this, and after more than 10 years of PHP I still have the tendency to write `if ($object !instanceof MyClass)` anyway. Would it be possible, or would it collide with constants to do the following? ``` $object === MyClass; $object !== MyClass; ``` The reason I'm hoping this would be possible, is that I often have brainlag trying to write "instanceof" and I either make several typos, or I end up with "instance" and it takes me an error message to realize I forgot the "of". The "instanceof" is counterintuitive for me compared to operators.
If this isn't possible and `!instanceof` would be adopted, what about the following in addition to the proposed example? ``` $object implements MyInterface; $object !implements MyInterface; $object extends MyClass; $object !extends MyClass; ``` On Mon, Dec 13, 2021 at 11:53 AM Oliver Nybroe <olivernyb...@gmail.com> wrote: > 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) >