Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107525 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 76417 invoked from network); 11 Oct 2019 21:39:00 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 11 Oct 2019 21:39:00 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 86CB22D1FDB for ; Fri, 11 Oct 2019 12:22:12 -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=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS11403 66.111.4.0/24 X-Spam-Virus: No Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (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 12:22:11 -0700 (PDT) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 3B09621EAD for ; Fri, 11 Oct 2019 15:22:11 -0400 (EDT) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Fri, 11 Oct 2019 15:22:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=vVZQuw NO0+XUNZRV8F9jt2BtgK0ayHDvPxtFvPGnuss=; b=SYwBD9iXy4iubXdAxV814j QG+w2uePAwG8Ger8qBPUUXeCq6+ULQO8tLnKkJOdHWaHfQ8SZcUG9zr+qx78siHk 8LUBdigd6By9XYTtSirEF4dKcMO7qFrrtTettGXsKHsNPJI6IHytA7uFi8DqozRd pNkLLGzdEUo/ljpwBfeK5bnoH0moCU/mOtXDw7LJbaBVtKq51j4koBqaVLnQlgKR ElSXR/FpEBwR9XHMkQNtb5PCgdNd/9guy+cQBWYZ8E1LtHK9k05vErjGf6ITy7Cc QQUxLOS6G9Jhajr3BKcYv522A2p2PRSWn7DW5Ij8DUnWZ4l28rIIJuWe61HaFYEw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrieehgddufeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucffohhmrghinhepghhithhhuhgsrdgtohhmpdhsthgrtghkohhvvghrfhhlohif rdgtohhmnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlug htvggthhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id D0F2B14200A1; Fri, 11 Oct 2019 15:22:10 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.1.7-360-g7dda896-fmstable-20191004v2 Mime-Version: 1.0 Message-ID: <037fd799-75e8-4900-a706-d9df7eeaceb9@www.fastmail.com> In-Reply-To: References: <237dbf6e-cd91-4e6d-8c97-1fbbabcd9f21@www.fastmail.com> Date: Fri, 11 Oct 2019 14:21:50 -0500 To: "php internals" Content-Type: text/plain X-Envelope-From: Subject: Re: [PHP-DEV] Warning for "confusable" types From: larry@garfieldtech.com ("Larry Garfield") On Fri, Oct 11, 2019, at 1:46 PM, Bishop Bettini wrote: > 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 OK, so it's just taking an existing error message and customizing it in cases where we have a good idea of what the user got wrong? That's a very +1 in my book. --Larry Garfield