Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107548 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 70926 invoked from network); 14 Oct 2019 17:06:15 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 14 Oct 2019 17:06:15 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 8DFD82C0530 for ; Mon, 14 Oct 2019 07:50:10 -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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: X-Spam-Virus: No Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) (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 ; Mon, 14 Oct 2019 07:50:09 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id y3so16937530ljj.6 for ; Mon, 14 Oct 2019 07:50:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8gkVBlNMuqVpSWVDONGfh5GqhsoWR1HhQITYep8XCJ0=; b=FFH25+UKGTufbV6lGTrLcelcmeGIh6ESd0yZihqGPEwsbV+nfaIm/8HCsChOHg7HSP 8pyKg770l1/AaKKKR3erlU8Wmfyr5CJuMzYu1vXv0fyg6Q28jFe48d+ncmCpJxfIx4as 82LJkEgnKrIdn8WbJgsBQpwuTVeqyNp2YANp4n3OopwxZi72Lz488J0XymZcpnKpoJnE W/5qwYXSW8Rxmtf8KedCEVMlOiLMqDR2jUkwMPqFQV+sGMmTy7Gw3esZyPCP3LCBaC7G mUZ2gMHZd5h2h3FeyNURYDEsZOYA0lxSbXwOZjIoV+P9JbvS0Jo4BBmNJPmyhiNZOnTO XyWg== 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:from:date :message-id:subject:to:cc; bh=8gkVBlNMuqVpSWVDONGfh5GqhsoWR1HhQITYep8XCJ0=; b=VeVQfwEFVstOF67+/HU6L0RphjUgI54Iq4SG7W0r8NQE2g6FMXqxKQxY9VySg1sJjz BP0RDehJZNWuZZ4h3G9QJ7Nd5Y9xBQOy1dxPLte5ah153wmVMWY1S9OlDrRbCZLpDH9a yX88HjQq29k3Vzpn5xUBChWHxk4C2ePfxM16QjBYlwD28skVagLUtfKs2m1DugrScw64 un+LdE4YexHLkOrT5q9EA6GpJknfiAfPjRlhU8lG30xgnIvgcTAXnXU0kxYdvXIo+eA/ tW9Uajpgb6trjkIb245X55tRO+9TXG9McYy/93qjrq1hcPdvwxv3CypMw19oUPLrrmum m32A== X-Gm-Message-State: APjAAAUPi4ynrEHoSOpP2rLd7Ms+94+EQ3pd5I5Oo9e40YeK+WC/Ct4u 0biA/yQsaJ5T1xB3f9YWk1tlJlh4d0YQDNc0fsI= X-Google-Smtp-Source: APXvYqw4YxkYSmqNT0lzThPrNgCb874RTb19cf+LBTcbBKSknvqs/uDB3ZsqBX2cD1ssrVlSwyTeyJGEClbMtJTaVJE= X-Received: by 2002:a2e:2b94:: with SMTP id r20mr18913289ljr.119.1571064608354; Mon, 14 Oct 2019 07:50:08 -0700 (PDT) MIME-Version: 1.0 References: <9668613b-5e9d-e67f-6001-3d360775eefe@gmail.com> <41aa6793-84da-ee39-8425-8a2240fd5b72@beccati.com> In-Reply-To: <41aa6793-84da-ee39-8425-8a2240fd5b72@beccati.com> Date: Mon, 14 Oct 2019 16:49:52 +0200 Message-ID: To: Matteo Beccati Cc: Stanislav Malyshev , PHP internals Content-Type: multipart/alternative; boundary="000000000000e677290594dffb0e" X-Envelope-From: Subject: Re: [PHP-DEV] Warning for "confusable" types From: nikita.ppv@gmail.com (Nikita Popov) --000000000000e677290594dffb0e Content-Type: text/plain; charset="UTF-8" On Mon, Oct 14, 2019 at 9:21 AM Matteo Beccati wrote: > Hi Stas, > > Maybe we should just change the error message to this?> > must be an > instance of the class "resource", but resource type is > given> > OTOH, since there are actually no resource type hints, and > naming your> class "resource" is an extremely bad idea, having a warning > there> wouldn't hurt too. > I was about to give my +1 on the more generic approach, but type hints > could also be interfaces and "instance of the class X" is not a good fit. > We've tried to improve these error messages a couple of times already, which is why it now say something like "an instance of resource, resource given" rather than just "resource, resource given". This does help, but there's a couple of disadvantages of trying to clarify the error message when a type error occurs, rather than throwing a warning during compilation: * The error is introduced during the function declaration, because that's where the incorrect type is used. Later errors will generally point to uses of the function, which is not where the error lies in this case. * There are many different errors that can be triggered. There's argument types, return types, property types, reference types, as well as things like default values (something I saw recently: Someone being confused about why "public double $foo = 1.5" throws an error.) All of these use different error messages and it's something of a loosing battle to try and address this issue in all of them. * Changing type errors is extremely costly, both as a one-time cost (test updates) and in terms of maintenance. The current type errors we throw for function arguments and returns are quite specialized, which makes it unnecessarily hard to incorporate future type-system extensions. For property types we went down a much simpler route of just printing the canonical type name and not specializing anything, which would get ugly pretty quickly, especially for reference errors that involve more than one type. This is why I think that this confusion needs to be addressed at the root, when the type is actually used, not at some later point. Nikita --000000000000e677290594dffb0e--