Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103299 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 78885 invoked from network); 1 Oct 2018 17:55:20 -0000 Received: from unknown (HELO mail-ot1-f41.google.com) (209.85.210.41) by pb1.pair.com with SMTP; 1 Oct 2018 17:55:20 -0000 Received: by mail-ot1-f41.google.com with SMTP id e21-v6so13134928otk.10 for ; Mon, 01 Oct 2018 07:04:44 -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=+POmFkJDuspLaa/xvg3P8c+ec4B3QhCDfKr6aPxXaT8=; b=QDKY6lcmnG8YZQW2uVM994kp0FIrzrODSTsTHaEaEojyA+kJqfxCZm1dTqJW5o4Ce/ 3DqkOuUp1JeND3LlaT/YxljDbn+xSPcd9GQKNsipyzjdKwez9Voo57ihBEHx2QVveOMQ yhuwju6FXu0WkTcSGXeZkiPUNlU/JebSWdN5OmoSDwDDfBO9q1BON8Xj90NxWpo74FaP ESbyB6ZrYvsKnEGkZnJCEDFL3EXFtk8HA4C+ZZq4gemzm4yDiivb6dnuLuUY1+YJk0nv Q4DA5YJGym7cpOLV06fPzcQKgFA2lE16UIIPhokonLQ2ujNQ/HjVOsISn+qaXCwmQ7sb U8SA== 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=+POmFkJDuspLaa/xvg3P8c+ec4B3QhCDfKr6aPxXaT8=; b=SOYfBO1e3GONrHM695YedbRkheEY4tS0B23ZgmEhfGzpT1/mr+YSl5dTYW6kDLWOG8 AdxQDqYK/BZ0Y1/Cpi5uEWiThA1Xn3JTOfjeCnAIx+HWxOpiGiX1toe/1yIX1tPo85qy w/84jvvy5JZXI6I7L+Zq73w+dRRBl8qUHiG9yBqoLn4T74Bd4/o9SBS7Yb8BCz2vYE3G dSDl8dCQANRJ+FQTuvzUGL1dHtDWSqRVAcbXQOF6R0bQRCxSkpvEVWFQLXMuIsnTQBlA eMlzLreZDZim4qp1PV7nNLkA1ZBx21tu/iGHVcSZ6o4vY7+V7Ak04NJqoYSfCBPb9/F3 +LZg== X-Gm-Message-State: ABuFfoj+CDB9rM92BhV6IPyX0yblbHshIEbgbw9dIhkgTQtDUsmaG+xP WVcEksYZu0FUsVH/hYnIRLRqPdkLIhOVLeE23gg= X-Google-Smtp-Source: ACcGV615WIFsuIEcHDHWGhOulrzYlqe3hK1ZE0vF/4ECgUIm57ABBGm5JcV6Kb9WTl05d/qZ96VgeXCa1+RAC6nuIsc= X-Received: by 2002:a9d:5092:: with SMTP id b18mr1652046oth.218.1538402683552; Mon, 01 Oct 2018 07:04:43 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 1 Oct 2018 11:04:32 -0300 Message-ID: To: rowan.collins@gmail.com Cc: internals Content-Type: multipart/alternative; boundary="0000000000007997a305772b4937" Subject: Re: [PHP-DEV] Class name resolution for \array::class From: marcospassos.com@gmail.com (Marcos Passos) --0000000000007997a305772b4937 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > > - It doesn't protect against typos like a constant would, because > \itn::class will reliably and silently resolve to 'itn' whether or not su= ch > a class exists. It's a good point, I didn't realized that. Having a ::type pseudo-constant is preferable, indeed. The whole point was about making it consistent before you stated that this use case become valid by mistake. Em seg, 1 de out de 2018 =C3=A0s 10:52, Rowan Collins escreveu: > 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 su= ch > 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 work= s > by mistake, as demonstrated by array::class not being supported when the > feature was first added. > > Regards, > -- > Rowan Collins > [IMSoP] > --0000000000007997a305772b4937--