Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86171 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42298 invoked from network); 12 May 2015 18:28:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 May 2015 18:28: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.45 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.45 mail-wg0-f45.google.com Received: from [74.125.82.45] ([74.125.82.45:36212] helo=mail-wg0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 18/00-41925-76642555 for ; Tue, 12 May 2015 14:28:55 -0400 Received: by wggj6 with SMTP id j6so19521161wgg.3 for ; Tue, 12 May 2015 11:28:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=user-agent:in-reply-to:references:mime-version :content-transfer-encoding:content-type:subject:from:date:to :message-id; bh=9l55P3acscNA9zJhNkZQzvlSctGA5RCmNmxgHfhOif4=; b=clc25PhrnpA+E945Ot0mvmMB02nwLmD+6VuRS7RFKE8JU53B+I+K4h/h20aU5058jD YSbTtXjobmDCEMb8CKHQ8XZhyQrxLPgmYUwv3STsGmoyoaYRdcx98e5+daHMlOYBPSzS mkmwZ2EIA2U7fOTYu1L28jEtZ+a24lVIVr28QSVFIzRCKdJVXa/QUiYDtqzUKevxnsb0 gDUQW2VMAf/ubHMfWCt0ot+EFmkufyiTq03ZqnxoziQge/dL9bNXR2d2Fje2toyNIbRx ZDEAN6IgszmgpIk8tPw1YcihtC7N6KzzO/Orqg9g8HaL5zD59Op3MoGBFQ0YQjmN3Djy sw4g== X-Received: by 10.180.219.42 with SMTP id pl10mr7595884wic.70.1431455332593; Tue, 12 May 2015 11:28:52 -0700 (PDT) Received: from [192.168.0.6] (cpc68956-brig15-2-0-cust215.3-3.cable.virginm.net. [82.6.24.216]) by mx.google.com with ESMTPSA id l20sm28955129wjw.42.2015.05.12.11.28.51 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 12 May 2015 11:28:51 -0700 (PDT) User-Agent: K-9 Mail for Android In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Date: Tue, 12 May 2015 19:26:44 +0100 To: 'PHP internals' Message-ID: Subject: RE: [PHP-DEV] nameof feature From: rowan.collins@gmail.com (Rowan Collins) On 12 May 2015 17:08:16 BST, Alexandr Marchenko wrote: >Idea of nameof (at least in my understanding) is to reduce string usage >and replace them with “strongly” typed “pointers” which can give us >feedback while script is processed (like when you misstyped method name >php will give you fatal error). The validation part makes sense, but from the description linked, there are no pointers involved, it just results in an ordinary string. In many cases, the string is only needed in the first place because there isn't a way of getting a better pointer - e.g. when passing in a class name to a factory, or a method name to some dynamic call mechanism. It would seem like a better idea to tackle that underlying problem, with some mechanism for passing classes, methods, etc as first-class types. The example in that blog post of accessing a parameter name seems very ugly to me. If a function takes positional, not named, arguments, then why should any outside code *care* what name they're implemented under? There is no wrong answer to "what name should I mention in this error message?". With named parameters, that all changes, because names become part of the signature, not the implementation. My current feeling is that parameters should be named independent of the local variables they assign to, e.g. function foo($bar as x, $baz as y) { return $bar / $baz; } foo(y: 42, x: 420); // 10 In which case, you'd sometimes want some equivalent of nameof($bar) to give you 'x', which would be very messy. Regards, -- Rowan Collins [IMSoP]