Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116636 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 89491 invoked from network); 13 Dec 2021 10:08:51 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Dec 2021 10:08:51 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 53F181804D4 for ; Mon, 13 Dec 2021 03:10:32 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-io1-f47.google.com (mail-io1-f47.google.com [209.85.166.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 13 Dec 2021 03:10:31 -0800 (PST) Received: by mail-io1-f47.google.com with SMTP id x10so18010550ioj.9 for ; Mon, 13 Dec 2021 03:10:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=V3qrnlwwTx7OiMMacQQDaq+XpHkBIuFug1vAoTq3aOc=; b=RNRFsS1AxvbqPLRuVTs7/fux0uYOWjMSAyFmFkBTfV66iGZhe+g2yFWbpHiwxel/DV 7StxAUqcYSeYrOm9k3CXnqCvTfKbv/kRF+Nfb65cqzGRqcnH/IiLJU6XlVTWFpm0VQhM k62MV/6uA+sMEN/P4vDfANhuUfa6syL0ZhodXejFpWJfJZxGCTEqFkNQMm9U7Mh6OeW9 NsLZSblkPWtRr8Ug/u80El0GWqjTCtIVJi5Akr03+YatJ1rxOEyRqPlgrNcOqrblSRVg o/Wzn84ZwvTnNxNDlyEUWtbxnH5dXgjBjEKMKY70TNk5COkIhp0vNGSK4EQLHSLB49W7 3jag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=V3qrnlwwTx7OiMMacQQDaq+XpHkBIuFug1vAoTq3aOc=; b=0eSOJB2vZGIuVZS2xTnh/Czn47ubiKlCoCYV3hg3vrZLybwzTgW4RgKyf1MLYICBVN RGx6fP+yLj09EBjONiPtkREnBcXOli6XaQVQgTs1XzGmY9IJKqXaCedqp3yOCJDohWcF l+t4+2Iq8TkDdNfRb9YlVb3vmlO3f0lxMV0QteGVzct6E4QJEzIcMufNZPGv4ZN7N1Dl cToXzdtU9XJ8zdP/JEcpc01eC/a/NfK86I2QNwo6otlcLq4J7LfzXM6xNeZIMhqUvDMR xvP8I69sKkB+IZnS1/QHYoj7t1fenAZpNYTUrYj7b3ozmiocS0zcxsjanFbxduzi0zkN yaEg== X-Gm-Message-State: AOAM5312ll/tpU6r687s2C+j59H7bAkAy5Hv6Qo3THcRCNaK9VD56l+u kHkpGdySb+l03tc8/VxlUy9tKnhULmMEH5jNd4c= X-Google-Smtp-Source: ABdhPJwfiR6nzD2Hknzpd7bBMwRsaZcku4oOMl4LVaINK7KVe+KQycruQ2RvCSOYpKb5iylKYYdB8FLEojRDF5WOHC4= X-Received: by 2002:a6b:8ed4:: with SMTP id q203mr31535886iod.200.1639393831335; Mon, 13 Dec 2021 03:10:31 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 13 Dec 2021 12:10:05 +0100 Message-ID: To: Oliver Nybroe Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000f6bf8a05d3051e13" Subject: Re: [PHP-DEV] [RFC] !instanceof operator - reaction measuremen From: kjarli@gmail.com (Lynn) --000000000000f6bf8a05d3051e13 Content-Type: text/plain; charset="UTF-8" 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 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) > --000000000000f6bf8a05d3051e13--