Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85031 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80606 invoked from network); 16 Mar 2015 11:44:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Mar 2015 11:44:44 -0000 Authentication-Results: pb1.pair.com smtp.mail=inefedor@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=inefedor@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.44 as permitted sender) X-PHP-List-Original-Sender: inefedor@gmail.com X-Host-Fingerprint: 209.85.215.44 mail-la0-f44.google.com Received: from [209.85.215.44] ([209.85.215.44:33293] helo=mail-la0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 07/52-03331-B22C6055 for ; Mon, 16 Mar 2015 06:44:44 -0500 Received: by ladw1 with SMTP id w1so36943125lad.0 for ; Mon, 16 Mar 2015 04:44:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:to:cc:subject:references:date:mime-version :content-transfer-encoding:from:message-id:in-reply-to:user-agent; bh=eS6wgPrf0oF2IvHgfcF8j4QjiqO7SowHc6zwVl0vIdU=; b=fj6d+NkAx859epld+U0Z0jOsTKSbNMAWCMFWKD2Ob1Bsoc9e+hqtspt1PhVUdJ1hQe bxWfyJjQzRdOxLVm/zWxhiYT4XqE7jowhy+QscfcGDTM3v3KCVMqrJL4ZGZydYgioDMs ivAhpJMfBkKVq3utK0VHUDGXQPEDhurWNcsPvuWWEaq3q/zi4p2zgvGKcFgzFQxE+wbr RxVUgL2i9HI6s5+QNS7xRWyiG04dTu+6RhSooJrPVn3hnfIbvUyEj9Rp8nVkbkOzKEaO BciHVjgVDPHtQP2Oiata+JvAfe0odYD6CbWPMMUyIn+qrdG3ZzzTnWjQ/8sQLagMvQbN pLPg== X-Received: by 10.152.163.2 with SMTP id ye2mr31476898lab.89.1426506281039; Mon, 16 Mar 2015 04:44:41 -0700 (PDT) Received: from nikita-pc ([89.250.5.98]) by mx.google.com with ESMTPSA id xl2sm2151191lbb.6.2015.03.16.04.44.39 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 16 Mar 2015 04:44:39 -0700 (PDT) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: "Yasuo Ohgaki" Cc: "PHP internals" References: Date: Mon, 16 Mar 2015 14:44:49 +0300 MIME-Version: 1.0 Content-Transfer-Encoding: Quoted-Printable Message-ID: In-Reply-To: User-Agent: Opera Mail/1.0 (Win32) Subject: Re: [PHP-DEV] About declare(strict_types = 1) From: inefedor@gmail.com ("Nikita Nefedov") 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 rea= son >> to vote against (or for something). What is important is how many peo= ple >> would actually benefit from a feature, without it causing issues for >> others. I am certainly no fan of the "declare" *syntax*, but I do kno= w, >> from talking at conferences that many many developers would like to s= ee >> scalar type hints in some way =E2=80=94 both weak (mode 1 of the STHv= 5 RFC), and >> strict (mode 2). It even caters for people that don't want to use the= m >> 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 wha= t = is expected. Author of a.php acknowledges that all arguments in fcalls = from this file will be converted to appropriate types, this is basicall= y = how all 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 a= ny = 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.