Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85970 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57582 invoked from network); 27 Apr 2015 17:25:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Apr 2015 17:25:56 -0000 Authentication-Results: pb1.pair.com smtp.mail=ocramius@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ocramius@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.49 as permitted sender) X-PHP-List-Original-Sender: ocramius@gmail.com X-Host-Fingerprint: 74.125.82.49 mail-wg0-f49.google.com Received: from [74.125.82.49] ([74.125.82.49:34340] helo=mail-wg0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DE/19-17556-3217E355 for ; Mon, 27 Apr 2015 13:25:56 -0400 Received: by wgso17 with SMTP id o17so123950741wgs.1 for ; Mon, 27 Apr 2015 10:25:53 -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=NfnV+cquyx4aVDPloQcZtXptlhJ5kqU6QTKPLNmQbRI=; b=ntdcNn9G44hlkFNAda1IAewpfkwoKE6WPJb0K3Iox62m6HzzQ4tt+YwyoRCksa50cA FKHHgA9k5jUasugyRZnZXlUzQplC+F/Tcn52rxxhQ8tbowN0jPBKjcOfrOlCQYd8bB2y XepafYBBLZ/q3O1vwhRKb/vXLVNFGJ2ep+U8BR/bYJmfmz5IjzoHi10JtlrngDjzF04M 2nf3DrMgqiCzkoTnCmBHBeU/AZMguG1tzF8sk3KYPHGviXZL2Xum9eSwPcv2c6ameQLy rlBexiEg7ci1ArZEFuC41yn70fjqAZzaEwY3qYKNZz8VeaFpKcu7C05pMWz6FktgnlV6 oukg== X-Received: by 10.180.90.82 with SMTP id bu18mr22444488wib.88.1430155553339; Mon, 27 Apr 2015 10:25:53 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.48.198 with HTTP; Mon, 27 Apr 2015 10:25:32 -0700 (PDT) In-Reply-To: References: Date: Mon, 27 Apr 2015 18:25:32 +0100 Message-ID: To: Anthony Ferrara Cc: "S.A.N" , internals Content-Type: multipart/alternative; boundary=f46d043893fbbafdce0514b8096e Subject: Re: [PHP-DEV] Add support $object::class From: ocramius@gmail.com (Marco Pivetta) --f46d043893fbbafdce0514b8096e Content-Type: text/plain; charset=UTF-8 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. Systems that depend on `get_class()` a lot would benefit from such a feature: see for example mapping caches in data mappers and handlers matching in event handlers. Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ --f46d043893fbbafdce0514b8096e--