Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103298 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 75896 invoked from network); 1 Oct 2018 17:42:44 -0000 Received: from unknown (HELO mail-io1-f52.google.com) (209.85.166.52) by pb1.pair.com with SMTP; 1 Oct 2018 17:42:44 -0000 Received: by mail-io1-f52.google.com with SMTP id w16-v6so9427859iom.7 for ; Mon, 01 Oct 2018 06:52:07 -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=0cDK6XwRDIG7tZTpd2EAjBKgY0M6BLLPnk3qU4nh0K8=; b=hPHy2HxF0v4/qUwGDvMTBx2uxgmdzkKVgjRSAZTg3xRc+tR9gmZiVPwPf85lz844kE ShUyDecvO9D/1plxrpmkH/Va9Sn/gIoI7fdV6ZP59U8QJnV9hm+wvzhYfWil/2f680CI 89eQyg8EBLd0Y6R18WI2P3Hu5kxKEq+Kd0cFK22ZNenC7HJdKYHw1rr92EjOwBA45A2Z 99tbDDUeVYj4+BYU5uqje4XGIuzrysZaMlqh7pTrrwI/xnAQ3D8Mh4a9xZyt8LFovPjn 8xDeYRI/qKkNi04YI/8FFZ4JMNt3H0DcsT95Ey5DckWkJANMPNc3eQtrMOYZ7THccqj7 lPSA== 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=0cDK6XwRDIG7tZTpd2EAjBKgY0M6BLLPnk3qU4nh0K8=; b=BuL8Bmw1qIuXlWQ/MmBevivVzM0a49yZXreLfjEIOrcWqDjuuWPHqFQTTbxQrbNyC7 k/aEBpZjMGI2ygl0m2jgFZOlEM96+SDjuriFfW3vZbbNoEyEgvDdVyIVTPS9Mtp9Hudv Ylf4TjcLqeutRzOx9tDIqtAi7rKlL6l2J0PWBTxK5n7lryVV7SS2EKEb0QnCUpx3P9tO fAjxkM2i0P9aXj+pFJnMPBXCxzxpal2PSnOPeRb0V1+hyQYza1PiqtL/heJr804VOKoN 9wMcpK93rHQJ1NQCtT3Q+RvzARIHX95PoQ72dWyK9Hck1q7U+Yv1QFyWaD6TbCi27MKI VUQQ== X-Gm-Message-State: ABuFfoiBkL8Pht/Ur/zMPsCTgRE4tq5OXkBQ/FfcyQwSOfj01s+TGI7h 06y29IH+4KKOCPTys2X3VlJxIH9dWKOciH001NY= X-Google-Smtp-Source: ACcGV61SVfGdFTSuMfB6/artS8xDgM8dV59SDarUhC2Kz5tHK/ew0giVdGOkuvAfNS0ycentOy8Li43KyvtpPzezDhA= X-Received: by 2002:a5e:df0d:: with SMTP id f13-v6mr5487245ioq.235.1538401927236; Mon, 01 Oct 2018 06:52:07 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 1 Oct 2018 14:51:55 +0100 Message-ID: To: marcospassos.com@gmail.com Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000650f4305772b1cfa" Subject: Re: [PHP-DEV] Class name resolution for \array::class From: rowan.collins@gmail.com (Rowan Collins) --000000000000650f4305772b1cfa Content-Type: text/plain; charset="UTF-8" On Mon, 1 Oct 2018 at 14:30, Marcos Passos wrote: > Sorry, it looks like I've replied to Marco only. > > About use case, we use it to specify types in standardized fashion: > > if (!$value instanceof Foo) { >> throw InvalidArgumentException::unexpectedType($value, Foo::class); >> } >> if (!\is_int($value)) { >> throw new InvalidArgumentException::unexpectedType($value, >> \int::class); >> } >> >> $converter->convert($value, \int::class); > > This is just obfuscation for no gain, IMO: - \int::class is 6 characters longer than 'int', and guaranteed to have the same value. - It doesn't protect against typos like a constant would, because \itn::class will reliably and silently resolve to 'itn' whether or not such a class exists. - It implies that "int" is a class, which it is not; and that the methods always take a class name, which they do not. > I also said that it might have some benefits for generic types: > > I don't disagree with you, but it's already supported right now, so what >> I'm only proposing to make it consistent. >> Looking forward, supporting name resolution for primitive may have some >> benefits for generic types >> >> . > > I note that in that discussion, the suggestion of ::type has already come up, and given its own thread: https://github.com/PHPGenerics/php-generics-rfc/issues/27 In my view, that would make more sense than officially supporting "::class" for things other than classes. > Beside this, deprecating it now would represent a BC break, right? > Nit-pick: deprecation is never a BC break; it just implies eventual removal, which is. But yes, outright banning it now would be a BC break. IMO it should have been banned at the same time "int", "string", etc were made illegal class names (in PHP 7.0), but I can see an argument that our next chance is PHP 8.0. I still think removing it is the right thing to do, however; it only works by mistake, as demonstrated by array::class not being supported when the feature was first added. Regards, -- Rowan Collins [IMSoP] --000000000000650f4305772b1cfa--