Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99757 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 37190 invoked from network); 5 Jul 2017 10:24:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jul 2017 10:24:50 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.43 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.43 mail-wm0-f43.google.com Received: from [74.125.82.43] ([74.125.82.43:38857] helo=mail-wm0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CF/CA-15131-D6EBC595 for ; Wed, 05 Jul 2017 06:24:46 -0400 Received: by mail-wm0-f43.google.com with SMTP id f67so107923746wmh.1 for ; Wed, 05 Jul 2017 03:24:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:user-agent:in-reply-to:references:mime-version :content-transfer-encoding:subject:to:from:message-id; bh=A/0IBKDf2U+3SxBryONxdoeqxeXrVKmh57sSGYZb5zQ=; b=f/PSBmAZQNio/lfTMYZ7jx+UcvYu9hPas51DQc99cF7mR8lFN3xcrA/q2IGij9Rlo0 gEWJKECtNIqcBGP9v35ysHq9+A0obOY2raJb7qy5/Y8r2ckl44XLZNqedeZcQNMzH9fE D2nGf6GhO82bWvE9Odtd8B1nrT1QMEGUZFtwtGNtWj+Wf5gM0oFSOCFtXXnt0VMI51zL LekCHJmTuzXoGTxMTXJiTAmHxaYpq71FftJZm0bBfcAlotLbZG7XlcFE/uk44/iWn+79 Lwm94Lt4ZhA0FbD2S0DVwFF2/S1Je7NaIfXj6cTWAlY3vWn5olQQ5rzyCvhjqxiERI0K dEKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:user-agent:in-reply-to:references :mime-version:content-transfer-encoding:subject:to:from:message-id; bh=A/0IBKDf2U+3SxBryONxdoeqxeXrVKmh57sSGYZb5zQ=; b=gzBVNW8B2gAYkaH9CUlXun4Ov6qY6tjNc40w9/nLOdSNDNgDKyyvGTXSFhIn2TJ80P eXugZ6IlPYC6+Fa/CIQ7dSxnX5wMxObHQVFr+td9gp3Zp2HzWexKhk18Akr4hDlF1oN8 OAoCy3/WKXIaE+XuI6Q1UYOslKTfr9DaWliPcm7rDAnyh6hZ/+O13CrmjIpmo7nsXgKl NuDvT/h3BmRm5WvwskiMfDJ3ORlCfBasJun48gIM3QHr3iDHg7Va+hb4aHLm+B5ahtoy knEZlUo4XBuzJmMdpPckyq9B817c1j8I/hkHUqq+Fzkr0yKHn2PpzI4pZb8ffyfF8+Kp oFTw== X-Gm-Message-State: AIVw11186OwP1AFTvHjqR9VcyP/RXX45qvpqjy9Nkw4kC6VulnrIPRWw XKjk9vMxaQyD2JhF X-Received: by 10.28.228.134 with SMTP id b128mr13411221wmh.64.1499250282837; Wed, 05 Jul 2017 03:24:42 -0700 (PDT) Received: from android-c07b90b023759a5a (host86-160-21-49.range86-160.btcentralplus.com. [86.160.21.49]) by smtp.gmail.com with ESMTPSA id n2sm10686876wmd.19.2017.07.05.03.24.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Jul 2017 03:24:41 -0700 (PDT) Date: Wed, 05 Jul 2017 11:24:39 +0100 User-Agent: K-9 Mail for Android In-Reply-To: <827b77ce-f2b7-930a-34cb-ce11ebc2d531@php.net> References: <827b77ce-f2b7-930a-34cb-ce11ebc2d531@php.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable To: internals@lists.php.net Message-ID: <679F251C-FFDA-4D9A-A0C2-89AA767A2402@gmail.com> Subject: Re: [PHP-DEV] OBJECT_OPERATOR vs. DOUBLE_COLON From: rowan.collins@gmail.com (Rowan Collins) On 5 July 2017 08:08:48 BST, Sebastian Bergmann wrote= : >Is it intentional that the DOUBLE_COLON operator can be used on a=20 >variable that contains a reference to an object? > >class C >{ > public function m() > { > print '*'; > } >} > >$c =3D new C; >$c::m(); > >Until yesterday I thought that only the OBJECT_OPERATOR (->) can be >used=20 >on a variable that contains an object=2E https://3v4l=2Eorg/59Xap proved = me > >wrong=2E > >As the deprecation / strict standards notices suggest, though, $c::m()=20 >does not invoke the method m() on the object referenced by $c=2E It=20 >invokes the method statically on C (the class of the object referenced=20 >by $c): https://3v4l=2Eorg/19taB > >I think that using :: on a variable that contains an object should not=20 >"fall back" to a static access on the object's class=2E Instead the=20 >runtime should error out=2E > >What do you think? Hi Sebastian, Firstly, I'm not sure where you got the names you've put in ALL_CAPS from= , but they're not the official names of the operators anywhere I've seen=2E= The double-colon is technically the "Scope Resolution Operator", or intern= ally T_PAAMAYIM_NEKUDOTAYIM (which does mean double-colon)=2E It's describe= d in the manual here: http://php=2Enet/manual/en/language=2Eoop5=2Epaamayi= m-nekudotayim=2Ephp I too was slightly surprised when I first learned it could be used against= an instance as well as a class name, but there are situations where this i= s useful=2E For instance, accessing a class constant associated to some obj= ect when interacting with that object, e=2Eg=2E "$foo->doThing($foo::MODE_X= )"=2E If we could only use it on class names, we'd have to use the "::class" ope= rator to go from one to the other, like "$foo::class::MODE_X"; or perhaps w= e'd change that operator too and write "$foo->class::MODE_X"=2E That's not = awful, I suppose, but it doesn't feel like a big gain=2E We'd also need to consider the consistency of "parent::", which resolves t= he scope but *doesn't* force a static access, because you need to be able t= o call an inherited non-static member=2E Like most established languages and frameworks, we don't have the luxury o= f going back and changing old design decisions, we have to look at if and h= ow we should evolve from where we are now=2E I think removing this behaviou= r, even if we found something nicer to replace legitimate uses with, would = be a huge compatibility break, for very little gain, so is unlikely to get = anywhere=2E Regards, --=20 Rowan Collins [IMSoP]