Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75414 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 60866 invoked from network); 13 Jul 2014 15:17:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Jul 2014 15:17:19 -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.178 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.178 mail-we0-f178.google.com Received: from [74.125.82.178] ([74.125.82.178:54780] helo=mail-we0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7D/B8-16748-EF2A2C35 for ; Sun, 13 Jul 2014 11:17:18 -0400 Received: by mail-we0-f178.google.com with SMTP id w61so2207265wes.9 for ; Sun, 13 Jul 2014 08:17:15 -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=QUK8R27Uwkp7YMBB4fuUvSyzXu3E+/JRo+P6VN9x53I=; b=Eh5CXTTzPU7gcqhTzyN8Zca7yvI/3n9yf48wZzREHnZ1PunOX+0BaNKdidXl5yU96f 24LcWx0H76algNgpDd9xYxUrfGCxvT2kaiNPysOtLbYXuiU7mwBPxozmiVAv2VZq6NXa Cc9GCjN24D7fkMXi/3ZPXEzp7ao3mJfLvrFWZfgTjTwPUb0QFPiN1OGW8CBlKKTmYD0U iMtxQibOKqosblQKIqijpB9t1VtJwZozpWAx8yQbTeb+bNKfyD/AG9Sq6FtmpPA7+BIJ FrUu3Jm54yTQ2Sqdr+Noj/+UeL0znhxq3Zh5ifg9DQrJC7wN1O7PhdLb7Dwlk6/39bRf aoAA== X-Received: by 10.194.243.200 with SMTP id xa8mr3712830wjc.97.1405264635308; Sun, 13 Jul 2014 08:17:15 -0700 (PDT) Received: from [192.168.0.2] (cpc19-brig17-2-0-cust25.3-3.cable.virginm.net. [81.101.201.26]) by mx.google.com with ESMTPSA id gh16sm19904838wic.3.2014.07.13.08.17.14 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 13 Jul 2014 08:17:14 -0700 (PDT) Message-ID: <53C2A2F7.1000806@gmail.com> Date: Sun, 13 Jul 2014 16:17:11 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: internals@lists.php.net References: <08503591-EFC8-48E6-984E-FFC292C5EA5F@ajf.me> <027E65EF-C4FC-474C-92BB-D99EFADDEEED@ajf.me> <53C29EE4.3090808@gmail.com> In-Reply-To: <53C29EE4.3090808@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) From: rowan.collins@gmail.com (Rowan Collins) On 13/07/2014 15:59, Jocelyn Fournier wrote: > From my point of view, if the type annotations are doing implicit cast > (with or without E_NOTICE/E_STRICT warning), they should behave > exactly the same than an explicit cast. If it behaves differently, > I'll be really difficult for a developer to guess what will be the PHP > behaviour with this new syntax. The problem is, in PHP an explicit type cast never fails - (int)'abc' simply gives you the value 0, not an error. If you let scalar typehints just generate unchecked casts, we'd have this: wants_object(object $foo) { var_dump($foo); } wants_int(int $foo) { var_dump($foo); } wants_object('abc'); // fails with E_RECOVERABLE_ERROR wants_int('abc'); // succeeds and prints int(0) That seems both inconsistent and less useful than a hybrid juggling + validation approach. -- Rowan Collins [IMSoP]