Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107522 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 67584 invoked from network); 11 Oct 2019 21:03:56 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 11 Oct 2019 21:03:56 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id D678D2CB34B for ; Fri, 11 Oct 2019 11:47:08 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No Received: from mail-io1-f43.google.com (mail-io1-f43.google.com [209.85.166.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Fri, 11 Oct 2019 11:47:08 -0700 (PDT) Received: by mail-io1-f43.google.com with SMTP id c6so23514605ioo.13 for ; Fri, 11 Oct 2019 11:47:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to:cc; bh=uLatbIFfwVg3rsZ2RN6m2LTvjmYFzy9I6mx84jVa67E=; b=L6QfaTeviSDCRyvx8AsIFTPEFC5BAzGaJH/rcmvk0VOo1A5ObG1rY8yXl0E2Nsckdv kIRVepD/b7cC+qCwVJSP9t4DLFCAs/b+vspEni0ANQHNp2mh4Dpb4uW5ZxiXyz50MX3I 5c0jf8XqHhcTxN0PIA8TNilWU/8lU3IUq6DD3fIz6p+LiAZqkV/JbVTwLkOLrs7syVGh dZCWhDI+EHwm02UVM7VCjwIa1aTacXnCd3Ec8tJJfopmGVKR3tSr2hfleZvczOCgJ1+/ AiyBxfBdZF1H0nVSIGJ70gDu+ibsENrEYbTuU/M2H5SUhF39vW3qdqTgRVSdzt1d9A3E 3+KQ== X-Gm-Message-State: APjAAAUGm95GoMFxCN7dsUsJnjRscz7rE5cUGV0AwXgEAU5gekVEJqq7 q2uv1Za46r5A4b9m6tfKY+WT3LeSkCUVXFhcFhY= X-Google-Smtp-Source: APXvYqzj7UO24rAPcqL5Krg/lFqBGvq2Mb3AY7GyEZSSDR/DN8V79P9GO+5ULv9Reg65PZBOaNn2NeW+/2YgWkTWcaA= X-Received: by 2002:a6b:ed19:: with SMTP id n25mr8113947iog.289.1570819627435; Fri, 11 Oct 2019 11:47:07 -0700 (PDT) MIME-Version: 1.0 References: <237dbf6e-cd91-4e6d-8c97-1fbbabcd9f21@www.fastmail.com> In-Reply-To: <237dbf6e-cd91-4e6d-8c97-1fbbabcd9f21@www.fastmail.com> Reply-To: bishop@php.net Date: Fri, 11 Oct 2019 14:46:41 -0400 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000e64db50594a6f1c0" X-Envelope-From: Subject: Re: [PHP-DEV] Warning for "confusable" types From: bishop@php.net (Bishop Bettini) --000000000000e64db50594a6f1c0 Content-Type: text/plain; charset="UTF-8" On Fri, Oct 11, 2019 at 1:47 PM Larry Garfield wrote: > On Fri, Oct 11, 2019, at 8:54 AM, Nikita Popov wrote: > > Hi internals, > > > > Something I've seen play out a couple of times: Newbies try to use > > something like "integer" or "resource" as a type, and then get a > confusing > > error message along the lines of "must be an instance of resource, > resource > > given". > > > > I would like to throw a compiler warning in this case, that looks as one > of > > the following: > > > > > Warning: "integer" will be interpreted as a class type. Did you mean > > "int"? Use qualified name or "use" to suppress this warning > > > > > Warning: "resource" is not a supported builtin type and will be > > interpreted as a class type. Use qualified name or "use" to suppress this > > warning > > > > This warning only triggers if the type is lowercase (integer but not > > Integer), is unqualified (integer but not \integer) and is not imported > > (there is no "use integer"). This provides multiple ways to avoid the > > warning for code that does legitimately want to use lowercase "integer" > as > > a class type. > > > > Implementation: https://github.com/php/php-src/pull/4815 > > > > Thoughts? > > > > Nikita > > Can you clarify where exactly "compiler warning" would be displayed? Is > that an E_WARNING? How would I as a user see a message when I write > > function foo(integer $a) { ... } > It's an E_COMPILE_WARNING, and arises when the compiler sees you're type hinting for a class, but no such class loaded. This checks that given class against a known list of "probable mistakes" and provides guidance. Eg, I typed "integer $a" when I mean "int $a", and don't understand the current compiler warning: "Argument 1 passed to foo must be an instance of integer, int given" See also https://stackoverflow.com/a/40638544/2908724 --000000000000e64db50594a6f1c0--