Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85976 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75445 invoked from network); 27 Apr 2015 19:53:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Apr 2015 19:53:32 -0000 Authentication-Results: pb1.pair.com header.from=ocramius@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ocramius@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.181 as permitted sender) X-PHP-List-Original-Sender: ocramius@gmail.com X-Host-Fingerprint: 209.85.212.181 mail-wi0-f181.google.com Received: from [209.85.212.181] ([209.85.212.181:38004] helo=mail-wi0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 32/CB-17556-AB39E355 for ; Mon, 27 Apr 2015 15:53:30 -0400 Received: by wiun10 with SMTP id n10so3633363wiu.1 for ; Mon, 27 Apr 2015 12:53:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=RhURBjiOfm1lU5q0fbUNpxDSmLh74vfXNVeO/LKPqb4=; b=IQqJocdsgqzlAMHvXBws+WnqMavVFvdELLBfMSktuVFS5HnhvORevdJp0gTOcMGrSJ AK0OIWJCshgPjgOyreZ5J6DXOCdoa/HyXIQknUMATyA9jynHIML9QJbCdrtE3cNOyspT 3oLyyFaIe9r0N/wlkmtHviQ915WgmwveBolYkr0MbF+aeAzdPbgxFa7Iswez9ajku0nW HZaMSjQenW5J5OQ8whOlnM1FZTX/Ie0K6zfc6E4Y3Yj0Vjm4zDifdjt1Sl9cPHdLX/+u VxZTDo3SOPeyjUg4gFChD9aOrd6L8tydFBwAISV+cSjqwlDShhAec1Yfxma1Oq1NUh31 SiSg== X-Received: by 10.194.236.225 with SMTP id ux1mr25777212wjc.52.1430164407309; Mon, 27 Apr 2015 12:53:27 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.48.198 with HTTP; Mon, 27 Apr 2015 12:53:07 -0700 (PDT) In-Reply-To: <553E8258.7040004@gmail.com> References: <553E8258.7040004@gmail.com> Date: Mon, 27 Apr 2015 20:53:07 +0100 Message-ID: To: Rowan Collins Cc: PHP Internals List Content-Type: multipart/alternative; boundary=089e0141a15477dbbe0514ba191d Subject: Re: [PHP-DEV] Add support $object::class From: ocramius@gmail.com (Marco Pivetta) --089e0141a15477dbbe0514ba191d Content-Type: text/plain; charset=UTF-8 On 27 April 2015 at 19:39, Rowan Collins wrote: > Marco Pivetta wrote on 27/04/2015 18:25: > >> On 27 April 2015 at 16:35, Anthony Ferrara wrote: >> >> On Mon, Apr 27, 2015 at 7:18 AM, S.A.N wrote: >>> >>>> Now this code causes an error PHP 5-7. >>>> >>>> PHP Parse: >>>> Syntax error, unexpected 'class' (T_CLASS), expecting identifier >>>> (T_STRING) or variable (T_VARIABLE) or '{' or '$' >>>> >>>> Do not want to use get_class($object) >>>> >>> Why not? >>> >>> Seriously, why not? ::class was added because there was no easy way to >>> get from the symbol class name to the string representation of it (you >>> couldn't pass it to a function, etc since it would look like a >>> constant). So ::class is a purely compile time construct to turn a >>> literal classname into a string representation. >>> >> >> Mainly due to overhead. >> >> Having `::class` accessible even for objects and variables containing >> class >> names would be very efficient, as it saves us a method call for an >> operation that really doesn't need one. >> > > The overhead of function calls comes up a lot, and it strikes me that > optimising calls to built-in functions *as a category* would be better than > piling more special case syntax into the engine for every use case. > Yes, it could be done indeed. Presumably, $foo::class will never be as fast as Foo::class anyway, because > the latter can happen *at compile time*, since it needs only follow the > namespace resolution for class name "Foo" within the current file/block, > thus having effectively zero overhead once cached. > It will never be, but still, following works, and that means that we have some sort of inconsistency: http://3v4l.org/napVW Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ --089e0141a15477dbbe0514ba191d--