Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85033 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83997 invoked from network); 16 Mar 2015 11:51:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Mar 2015 11:51:00 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.46 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.218.46 mail-oi0-f46.google.com Received: from [209.85.218.46] ([209.85.218.46:33328] helo=mail-oi0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 02/13-03331-2A3C6055 for ; Mon, 16 Mar 2015 06:50:59 -0500 Received: by oibu204 with SMTP id u204so35117319oib.0 for ; Mon, 16 Mar 2015 04:50:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=mRtULf+RuVw7oA7ytDtwZP30efgvI6f2xb22vCJQ4zM=; b=A3aowIs5ovHQ9kilxepd5MSZp4woOExo3ceDIiSmmIVatgbkn2hNNfydWnydG40Acq mPix8xhJWZ93y2S8GcER3a5HfksHtQuo8pbT1h2MiItZeLdWp/5GEwJan8FhofyOj+s/ ekoiqX3RTZZu0fxrSYMRzBoUyHtxp7eciPNu5QxfrZ7pe44Ak2V18Fgg34xrguvxeolJ i/YRIBFXJZyZ5KE+kph2Xp0ohVXrivG9My4bTRMn0jp+Ti2Fslmpn3xNa9w1isOve7b1 wwdSVaGWra970DIlc8hDlvkjzGs/2wI74+so+aZwo9z48nijMC8vKKVp2h3V9w6kVbvV KY9Q== X-Received: by 10.60.62.42 with SMTP id v10mr47322880oer.45.1426506656142; Mon, 16 Mar 2015 04:50:56 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.202.58.2 with HTTP; Mon, 16 Mar 2015 04:50:16 -0700 (PDT) In-Reply-To: References: Date: Mon, 16 Mar 2015 20:50:16 +0900 X-Google-Sender-Auth: x0QYXMlZlkbpe_9mZgTIezotTd4 Message-ID: To: Nikita Nefedov Cc: PHP internals Content-Type: multipart/alternative; boundary=089e013c5ca8825cb505116676f4 Subject: Re: [PHP-DEV] About declare(strict_types = 1) From: yohgaki@ohgaki.net (Yasuo Ohgaki) --089e013c5ca8825cb505116676f4 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, Mar 16, 2015 at 8:44 PM, Nikita Nefedov wrote: > On Mon, 16 Mar 2015 14:33:00 +0300, Yasuo Ohgaki > wrote: > > Hi Derick, >> >> On Mon, Mar 16, 2015 at 8:18 PM, Derick Rethans wrote: >> >> To be frank, I don't think "I don't like this" is a terribly good reaso= n >>> to vote against (or for something). What is important is how many peopl= e >>> would actually benefit from a feature, without it causing issues for >>> others. I am certainly no fan of the "declare" *syntax*, but I do know, >>> from talking at conferences that many many developers would like to see >>> scalar type hints in some way =E2=80=94 both weak (mode 1 of the STHv5 = RFC), and >>> strict (mode 2). It even caters for people that don't want to use them >>> at all, as they can simply not use them. I also know, that without a >>> dual mode, it seems very unlikely for scalar type hints to make it >>> into PHP 7, and I don't think that is what users want. As this is our >>> *best* bet, I can only vote "yes". >>> >> >> >> Are you sure on your bet? >> >> lib.php: >> > declare(strict_types =3D 1); >> function foo(int $a) { >> // no function call here >> } >> ?> >> The declare here does just nothing. >> >> a.php: >> > require "lib.php"; >> foo("123"); // will work >> ?> >> >> b.php: >> > declare(strict_types =3D 1); >> require "lib.php"; >> foo("123"); // will give an error >> ?> >> >> This behavior is unacceptable. >> Caller (a.php, b.php) must satisfy lib.php expectation to make lib.php >> work as it should. Otherwise, all kinds of unexpected for lib.php and it= 's >> users may happen. >> > > When called from a.php, foo() will get and int(123), this is exactly what > is expected. Author of a.php acknowledges that all arguments in fcalls fr= om > this file will be converted to appropriate types, this is basically how a= ll > our internal functions work currently and it's perfectly acceptable. But = if > you don't want this kind of type juggling then you opt-in strict types. > This is basically as easy as it gets, I don't see any way to make it > simpler. There's nothing to evolve in this RFC, it covers pretty much > everything and the idea of allowing for caller to make a decision is, in = my > opinion, a great win in this situation. I already showed real world example how this could be fail. If we need this kind of behavior. I would suggest to have type affinity like SQLite for $_GET/$_POST/$_COOKIE. https://www.sqlite.org/datatype3.html This would work better to work with strict types. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --089e013c5ca8825cb505116676f4--