Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83091 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79825 invoked from network); 18 Feb 2015 16:33:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Feb 2015 16:33:50 -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:40242] helo=mail-wg0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3D/54-56339-DEEB4E45 for ; Wed, 18 Feb 2015 11:33:50 -0500 Received: by mail-wg0-f45.google.com with SMTP id k14so2240963wgh.4 for ; Wed, 18 Feb 2015 08:33:45 -0800 (PST) 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=6JJvqknfVxINfI0q4oB2nBELae5LbNAvkXRSXyd/LPc=; b=BaBUFoUJYSo5ZC/an0OdyJjDcUuLaTq3SujvhPQzeAbQBK6Y3zCNRg/kQ+FwkZKcpp pec9O0HZDTMuugFkqyrQL5tAblsSRRjal+0RgBr4ek5iH/R93J4usv0c15AGAbyee09y 2Mhqpt0lTWjnJtX/FbOcHtiBVZD1IX/PBFPwm3NiRiSGwslTjU5jyxw2yQmaoDGcJdP1 XLGIpoM+Dzvcj/xFjTyvrxI8CrH2zLfk5zt0eAj55TozQlWj9i9UIMl4cvx53pTbUqZf dpG9KA3Lr3C4RkiutkCPU8WBJl1brsNVdWvMDjPGXygWk2EcoR5ANTg4vTuNkSLzpw74 BhFQ== X-Received: by 10.180.108.178 with SMTP id hl18mr1652893wib.92.1424277225197; Wed, 18 Feb 2015 08:33:45 -0800 (PST) Received: from [192.168.0.172] ([62.189.198.114]) by mx.google.com with ESMTPSA id eb10sm30181148wib.13.2015.02.18.08.33.44 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Feb 2015 08:33:44 -0800 (PST) Message-ID: <54E4BEDA.70009@gmail.com> Date: Wed, 18 Feb 2015 16:33:30 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: internals@lists.php.net References: <032f01d04b92$2722e0d0$7568a270$@php.net> In-Reply-To: <032f01d04b92$2722e0d0$7568a270$@php.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Scalar Type Hints v0.4 From: rowan.collins@gmail.com (Rowan Collins) François Laupretre wrote on 18/02/2015 15:47: >> De : Leigh [mailto:leight@gmail.com] >> >> Can we keep a 0) of "reserve names for future use in-case of RFC >> failure" option. > Reserving names is only needed as long as we keep keywords sharing the same naming space as classes. This is a mistake from the past and, as long as we keep it, each new keyword is a pain. Reserving keywords in advance can only lead to reserving too few or too much. So, IMO, deprecating bare class names as hint is first. Then, we can reserve a limited set of keywords. What if we defined the types as names in the \PHP namespace, but defined a slightly different algorithm for resolving typehints vs other uses: function foo(\PHP\types\numeric $a) // unambiguous but unwieldy function foo(\My\Namespace\numeric $a) // unambiguously *not* a built-in type function foo(numeric $a) // ambiguous, resolved at compile time The name would be resolved as follows: Given a typehint $type: 1) If $type begins with '\PHP\types\', interpret it it as an internal type. 2) ElseIf $type contains '\', interpret it as a class name, and proceed with normal class resolution at runtime. 3) ElseIf \PHP\types\$type is the name of a built-in type, interpret it as that internal type. 4) Else, interpret it as a class name, and proceed with normal class resolution at runtime. Basically, this means you can do the following: class String {} function accept_scalar_string(string $string) { ... } function accept_string_object(\String $string) { ... } The nice thing about this is that if we ever allow users to define "basic" types - copy-on-write structs, range types, enums, etc - they could "extend" these built-in types. Does that make sense to anyone, or am I over-complicating things? Regards, -- Rowan Collins [IMSoP]