Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85975 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69903 invoked from network); 27 Apr 2015 18:40:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Apr 2015 18:40:56 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.52 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.52 mail-wg0-f52.google.com Received: from [74.125.82.52] ([74.125.82.52:32974] helo=mail-wg0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 89/FA-17556-7B28E355 for ; Mon, 27 Apr 2015 14:40:55 -0400 Received: by wgin8 with SMTP id n8so125761161wgi.0 for ; Mon, 27 Apr 2015 11:40:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=eaBprfaex3kvsos/p3OKnjv1yI4NtZgnZc+ziJT/Okw=; b=Z2JCIWl75huJwvBUGpV/BuIeYkErEzNjeC4BdRNa1Jwfa9GSCN8mnlLeo9E7hPfWDC YBFj3Y0lf/xLRovLU1iFgNMq/m96C6qGbtI+Uz6QxiskB+XV+lYIgPszj//tZsMBBqS3 cSLAgVRaUtn6IQkHF/HcAKwYC3QW8+NpvIYXxjRa5P68a3eWNWtOkF20ojJqCnaHfb72 eErgphUrH4hr84S6FvRAmkOSfBuCMu40T+YVoAfVDdZwtLxmE4bUVNzZFhFas9gUftZZ 4+ec/zGlS+EMYeTvXE0o5ptNq85czPHfjPDQQ9de+7fzBjWhJ3774UpffhLIIwRcfwe7 KqBg== X-Received: by 10.194.79.9 with SMTP id f9mr25424821wjx.20.1430160052227; Mon, 27 Apr 2015 11:40:52 -0700 (PDT) Received: from [192.168.0.159] ([62.189.198.114]) by mx.google.com with ESMTPSA id gi17sm30538029wjc.8.2015.04.27.11.40.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Apr 2015 11:40:51 -0700 (PDT) Message-ID: <553E8258.7040004@gmail.com> Date: Mon, 27 Apr 2015 19:39:20 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Add support $object::class From: rowan.collins@gmail.com (Rowan Collins) 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. Is this a fundamentally hard problem? Could there be some way of writing certain internal functions such that they're accessible as normal calls (for use with call_user_func etc) but also optimisable to something more similar to an opcode call (which seems to be the alternative) by the OpCache? 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. Regards, -- Rowan Collins [IMSoP]