Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75424 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76587 invoked from network); 13 Jul 2014 16:09:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Jul 2014 16:09:09 -0000 Authentication-Results: pb1.pair.com smtp.mail=jocelyn.fournier@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=jocelyn.fournier@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.182 as permitted sender) X-PHP-List-Original-Sender: jocelyn.fournier@gmail.com X-Host-Fingerprint: 209.85.212.182 mail-wi0-f182.google.com Received: from [209.85.212.182] ([209.85.212.182:51244] helo=mail-wi0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C6/1C-16748-32FA2C35 for ; Sun, 13 Jul 2014 12:09:09 -0400 Received: by mail-wi0-f182.google.com with SMTP id d1so1420842wiv.3 for ; Sun, 13 Jul 2014 09:09:04 -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:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=cwNkkbdPmis2tS+BzIgQ6CxnMQoIs54dRDhqRSsHtVY=; b=TWyGkFNX/LC8JZgSeatk2Z7l8qXnOcThi3N8y1vU1Q+9aC0dsIU3hiOC16k75OMpCH rVtOSjreBteoupA6Rd+oPjZOHAcVopBYoMucklystyHoxHxnCvz6ZCql9qV2pIEWyIJh rCF5/VAX6+Bs2cusYEDTgyvxKAcXKpL+Lpgp2191jdHATzy1PaSs6r1FvgZLz2Aq+6aV /IdeFVcod8hSVvMvwEY+D5hX0Hfe/AV+3jMJSfBQkhW4zD3ufFzrFg26ORLgZoyGQfq1 TzjbcDyPNhnAlEEtpWXGTt3ctPFz6Wc7jVXrTwnv4PeYOn6wDFW2TSBiPQfMYXkVUPo8 xE9A== X-Received: by 10.194.186.178 with SMTP id fl18mr12638649wjc.83.1405267744219; Sun, 13 Jul 2014 09:09:04 -0700 (PDT) Received: from MacBook-Pro-de-jocelyn-fournier.local (ven06-1-82-234-156-61.fbx.proxad.net. [82.234.156.61]) by mx.google.com with ESMTPSA id o2sm19525705wij.24.2014.07.13.09.09.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 13 Jul 2014 09:09:03 -0700 (PDT) Message-ID: <53C2AF1D.9070801@gmail.com> Date: Sun, 13 Jul 2014 18:09:01 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: Rowan Collins CC: internals@lists.php.net References: <08503591-EFC8-48E6-984E-FFC292C5EA5F@ajf.me> <027E65EF-C4FC-474C-92BB-D99EFADDEEED@ajf.me> <53C29EE4.3090808@gmail.com> <53C2A2F7.1000806@gmail.com> <53C2A753.2060001@gmail.com> <53C2AAF7.3060504@gmail.com> In-Reply-To: <53C2AAF7.3060504@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) From: jocelyn.fournier@gmail.com (Jocelyn Fournier) Le 13/07/2014 17:51, Rowan Collins a écrit : > On 13/07/2014 16:35, Jocelyn Fournier wrote: >>> That seems both inconsistent and less useful than a hybrid juggling + >>> validation approach. >> >> Than means you find currently inconsistant than >> >> $foo = (int) 'abc'; >> >> works but not >> >> $bar = (object) 'abc'; >> >> ? :) > > Well, the ability to cast to an object at all is pretty wacky, since PHP > has no standard base class for objects, nor any mechanism to cast to or > from specific classes, etc. > > Perhaps this example is more appropriate: > > function wants_array(array $foo) { var_dump($foo); } > wants_array('abc'); // Error > wants_array( (array)'abc' ); // OK - parameter passed is array(0 => 'abc') > > As you can see, it's perfectly possible for the value to be cast, but > the "type hint" does not do so, it rejects the value. If "type hint" is doing exactly the same than explicit cast, it should not fail on wants_array('abc'), but give a warning about the implicit cast conversion. Jocelyn