Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:77151 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55835 invoked from network); 11 Sep 2014 22:00:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Sep 2014 22:00:21 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.177 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.177 mail-wi0-f177.google.com Received: from [209.85.212.177] ([209.85.212.177:53648] helo=mail-wi0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6B/20-52095-47B12145 for ; Thu, 11 Sep 2014 18:00:20 -0400 Received: by mail-wi0-f177.google.com with SMTP id em10so7729wid.4 for ; Thu, 11 Sep 2014 15:00:17 -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=F7YkyDoBcWYdjnIe5mBVI+g10BT6f03Y1T/wBoSBVHw=; b=bRd6Gdy+cXHWt8wIRI4Z/BmfNE+gVGcmlnXTjfOS57isHzG/uX8ohxxWG6vE13/p/g uYvVqpYSDkTmSNYqxRxMIujYz7wn5/UziL8WXRGf78Zb0V4xU13RGzq4frszZEUSmuyS aWoG9o6yk/6eAV2RyEoUpV7F2Pl8nilEOXBzUJRtmanYYDC6QLTwfzBm4WjZCCRlFfcU rdP0GXWb9B87eKR5v3C3zAEJ12gFASskeQWHgmeblj+lED1ROaUgu2a15TNXDzOFQ7JB xf+gHLoaTmzSlQEar0kDhFxFXJzXGptbeK+AsTZuWXW+AD5aGRlEkNRRPVqcym/sXFY4 nB3g== X-Received: by 10.194.103.41 with SMTP id ft9mr5316599wjb.93.1410472817391; Thu, 11 Sep 2014 15:00:17 -0700 (PDT) Received: from [192.168.0.3] (cpc68956-brig15-2-0-cust215.3-3.cable.virginm.net. [82.6.24.216]) by mx.google.com with ESMTPSA id fx10sm6315903wib.18.2014.09.11.15.00.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 11 Sep 2014 15:00:16 -0700 (PDT) User-Agent: K-9 Mail for Android In-Reply-To: References: <004d01cfcc63$e7e3ac40$b7ab04c0$@tutteli.ch> <3DB7DEC9-2F99-4DDB-95A9-70455E4BABCB@ajf.me> <54108D63.3070707@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Date: Thu, 11 Sep 2014 23:00:13 +0100 To: PHP internals Message-ID: <9205aea6-7a4d-4848-8181-a56ecaadc905@email.android.com> Subject: Re: [PHP-DEV] make casts more strict in PHP 7 From: rowan.collins@gmail.com (Rowan Collins) On 11 September 2014 04:02:43 GMT+01:00, Park Framework wrote: >> You know, “int”, “float”, “string” etc. aren’t currently reserved >words. Well, they are in the context of casts: $a = (int)'42'; $a = (string)42; etc > We could add functions, or even make them reserved words and add >internal functions (à la isset), so int(‘2’), float(‘2.0’), >string(‘test’) etc. How would this be different from what we already have? For the function version (useful as a callback), we have intval(), strval(), etc >> >> Or perhaps class-like constructors? $a = new int('2'); ? Would kinda >make sense given some people want to add methods to primitive types. > >+1 > >$int instanceof Int >$float instanceof Float >$num instanceof Numeric >$bool instanceof Boolean >$str instanceof String >$array instanceof Array > >This makes it possible not to use the is_*() functions. >It is desirable to conduct instanceof fully consistent with behavior >hinting casts, it would be logical and correct. >Just wanted to be able to use these classes (or interfaces) to create >their objects, these objects would pass inspection in hinting casts. This could cause a lot of confusion. If these "constructors" are just a new syntax for type casting, there's no obvious reason to behave differently in terms of strictness, which is what we were discussing previously. Worse, they would look like objects, but behave as plain variables (no reference-like ability to modify the value in place). Alternatively, these could be special "boxed types", which were real objects acting almost but not quite the same way as the equivalent basic type. Some languages (e.g. Java) have those, but they're frankly rather confusing, and I'm not sure what the benefit would be. Regards, -- Rowan Collins [IMSoP]