Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86168 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 23385 invoked from network); 12 May 2015 14:58:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 May 2015 14:58:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=bishop.bettini@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=bishop.bettini@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.180 as permitted sender) X-PHP-List-Original-Sender: bishop.bettini@gmail.com X-Host-Fingerprint: 209.85.217.180 mail-lb0-f180.google.com Received: from [209.85.217.180] ([209.85.217.180:36208] helo=mail-lb0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3E/51-14268-31512555 for ; Tue, 12 May 2015 10:58:28 -0400 Received: by lbbqq2 with SMTP id qq2so7995804lbb.3 for ; Tue, 12 May 2015 07:58:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:sender:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=2xx04soKfcxGGvFJ592gJjLjkS7P4ueunvuEAKE0Il0=; b=kuZDaMnfuAZYgqiqbuSzvpF1yLzZ+Duyec8m2vSdk9GXVMph0ordA6eDA399Yje4Wn jNL/mmX+3/8lIaD0sUjjYoQLGlZcvVwqfuJczg0rebbSTg580fwQmydu75M5ZeHrbXTE OYRP9uicotQr5wuVNjgqCYnSHl3UaBtqsp85Mny/7P0G4x5iHOjPjs9m2WEncoqb8q66 G4xvAWwe/q+Y2zhufFUteWE0lI0f4CVkIL6wIh7Qh6ras7Zvd7I6qDdkvEaVoyCoay7T k5Xv10wo77XMnsT/LzJ6ZJL9z3b18/xPEg30Gokvozm+KxzaYsAUnvTzprlA1D1pPTiJ hCBA== MIME-Version: 1.0 X-Received: by 10.112.138.195 with SMTP id qs3mr11975327lbb.47.1431442704530; Tue, 12 May 2015 07:58:24 -0700 (PDT) Reply-To: bishop@php.net Sender: bishop.bettini@gmail.com Received: by 10.152.125.167 with HTTP; Tue, 12 May 2015 07:58:24 -0700 (PDT) In-Reply-To: References: Date: Tue, 12 May 2015 10:58:24 -0400 X-Google-Sender-Auth: iThRXO5OK7_xiWsFGAGd-t9Lzrw Message-ID: To: Alexandr Marchenko Cc: PHP internals Content-Type: multipart/alternative; boundary=089e011609d0eb845f0515e3b90f Subject: Re: [PHP-DEV] nameof feature From: bishop@php.net (Bishop Bettini) --089e011609d0eb845f0515e3b90f Content-Type: text/plain; charset=UTF-8 Hi! On Tue, May 12, 2015 at 9:29 AM, Alexandr Marchenko < marchenko.alexandr@gmail.com> wrote: > > Guys from C# implemented similar but more powerful feature: nameof(Acme), > nameof(Acme.AnyMethod) > > https://msdn.microsoft.com/en-us/magazine/dn802602.aspx > > Imagine how much confidence it will give you while renaming your methods, > class names etc. > Neat. So, how would that work in this scenario? class God { public static function create($method) { call_user_func([ 'God', $method ]); } private static function chicken() { echo 'Let there be chicken!'; } } God::create('chicken'); I understand nameof(God) would replace the literal string 'God', but how would one replace the literal 'chicken' with the appropriate compile time reference? Perhaps: nameof(God::chicken) Also, since nameof() is a compile-time conversion , nameof() wouldn't help a value construct like this: God::create($_REQUEST['animal']); So, overall, how does nameof(God) aid in refactoring more than a find and subsequent replace, like ag --php "'God'"? bishop --089e011609d0eb845f0515e3b90f--