Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58429 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16352 invoked from network); 1 Mar 2012 23:30:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Mar 2012 23:30:16 -0000 Authentication-Results: pb1.pair.com smtp.mail=simonsimcity@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=simonsimcity@googlemail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.214.170 as permitted sender) X-PHP-List-Original-Sender: simonsimcity@googlemail.com X-Host-Fingerprint: 209.85.214.170 mail-tul01m020-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:57843] helo=mail-tul01m020-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 26/70-13741-786005F4 for ; Thu, 01 Mar 2012 18:30:15 -0500 Received: by obbwd1 with SMTP id wd1so1427887obb.29 for ; Thu, 01 Mar 2012 15:30:13 -0800 (PST) Received-SPF: pass (google.com: domain of simonsimcity@googlemail.com designates 10.60.4.199 as permitted sender) client-ip=10.60.4.199; Authentication-Results: mr.google.com; spf=pass (google.com: domain of simonsimcity@googlemail.com designates 10.60.4.199 as permitted sender) smtp.mail=simonsimcity@googlemail.com; dkim=pass header.i=simonsimcity@googlemail.com Received: from mr.google.com ([10.60.4.199]) by 10.60.4.199 with SMTP id m7mr1304109oem.65.1330644613195 (num_hops = 1); Thu, 01 Mar 2012 15:30:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=k4i6wEV1Jg2OhScRukggZEjxuILYwcxzBcatpep8F4o=; b=LZ7KOjlPf3PJYOfdE3aGnPiq1gId5bC8RapgN2wzH6s9Q6dBahnRVrRKvxLEY96Vx9 315pgOgjdgYANniN2v2f66aIhbB2ASrtfp+imTzWyimUeRszGAfR2Hj+j/dM9kvu3FHH tEaEk8L5J7FSmH8OnHObm50XeegWxRXgxvO9g4nVqnkOoPD/gVaf1KR+2ZNCkFkXEIkf 6AbF13nqQhBu8iq+FfT6qxdnzCFHZvW1WPioOb470U74efzjF+YhQv6qTwUZLW0UFQ6j 5A/4Glxmxm3gGEE7v1ifyMjvo2vwr0XzCqP9K2oqAvokkkvtfNZlsDEuJERjGhyh+aWj sRJQ== MIME-Version: 1.0 Received: by 10.60.4.199 with SMTP id m7mr1122852oem.65.1330644613097; Thu, 01 Mar 2012 15:30:13 -0800 (PST) Received: by 10.60.7.229 with HTTP; Thu, 1 Mar 2012 15:30:13 -0800 (PST) In-Reply-To: References: <693e15008681dfe7372eaea66214f8a8.squirrel@www.l-i-e.com> <4F4D5D44.5090307@developersdesk.com> Date: Fri, 2 Mar 2012 00:30:13 +0100 Message-ID: To: John Crenshaw Cc: jpauli , Richard Lynch , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=e89a8ff1c1667c691204ba36d748 Subject: Re: [PHP-DEV] PHP Philosophy (was RE: [PHP-DEV] Scalar type hinting) From: simonsimcity@googlemail.com (Simon Schick) --e89a8ff1c1667c691204ba36d748 Content-Type: text/plain; charset=UTF-8 Hi, John Therefore I think it would be easy to explain how a type-hint for scalar could work. You can explain it as saying that the following two functions should be end up in exactly the same result, whatever you're pasting into: function foo_one(scalar $bar) {} function foo_two($bar) { if (!is_scalar($bar)) trigger_error("Catchable fatal error: Argument ? passed to ? must be a scalar, ? given,", E_RECOVERABLE_ERROR); } The error-message is just an example - but that would keep the three type-hint possibilities in one and the same functionality - like just allowing exactly this type. You cannot even pass a class that extends* ArrayIterator *into a property that requires an array. So I think we should also here (at least for scalar) do a really strict thing. Bye Simon 2012/3/1 John Crenshaw > > > > From: Richard Lynch [mailto:ceo@l-i-e.com] > > > > On Wed, February 29, 2012 7:16 pm, John Crenshaw wrote: > > > > > I'm beginning to think that the type hinting question is too > closely > > > > > related to the dirty secrets of type juggling to resolve them > > > > > separately. You may have to either discard consistency, or else fix > > > > > the problem of silent bizarre conversions at the same time > ('foo'==0, > > > > > '123abc'=123). Fixing the conversions is a BC break though. > > > > > > > > [short version] > > > > One man's "fixing" is another man's "feature" :-) > > > > > > > > Old hands can now hit delete while I wax philosophical. > > > > > > The operative word was "silent". The actual behavior is fine, but the > > > silence is unexpected. For example, PHP happily accepts substr('foo', > > > 'bar') with no complaint at all. From a purely philosophical > perspective I > > > think almost everyone would expect *at least* a strict notice. > > > > > > On a practical level, we have a major barrier and we'll have to decide > how > > > to handle it. As I see it we could do one of the following: > > > 1. Discard consistency (!!) > > > 2. Try to convince people to make these bizarre conversions not silent > (BC > > > break) > > > 3. Try to find a creative solution to be consistent without changing > > > anything about the conversion behavior. (I'm not seeing a way to do > this > > > one, unless we redefine "consistent".) > > > > > > John Crenshaw > > > Priacta, Inc. > > > > > > -- > > > PHP Internals - PHP Runtime Development Mailing List > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > > > On Thu, Mar 1, 2012 at 9:52 AM, Simon Schick < > simonsimcity@googlemail.com> wrote: > > Hi, John > > > > Just to add an idea to yours .. > > > > Do you think it's a compatibility-break if we'd decide to send a E_NOTICE > > or E_WARNING if we f.e. try to give a string to a method that just allows > > integer for this argument? > > No break at all, just a E_NOTICE or E_WARNING as the script can succeed > > anyways. > > Perhaps I missed something, but since 5.3, the new parameter parsing API > > throws a Warning when types are not strictly honored. > > This has been a major feature in favor of "cleaner" programming. > > > > Try substr('foo', 'bar'), in PHP >= 5.3 and you get a warning and the > > function returns null. > > > > Julien.P > > > > Bye > > Simon > > > > Ah, didn't notice the *new* behavior. That simplifies things substantially. > > I also had another realization today, which is that there's already strong > precedent for treating parameter hints more aggressively than a type cast. > For example, you can cast between arrays and objects, with no errors, but > the type hints will still generate errors. I think this settles the > consistency issue for me. > > John Crenshaw > Priacta, Inc. > --e89a8ff1c1667c691204ba36d748--