Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83778 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 33072 invoked from network); 25 Feb 2015 12:50:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Feb 2015 12:50:09 -0000 Authentication-Results: pb1.pair.com header.from=inefedor@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=inefedor@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.54 as permitted sender) X-PHP-List-Original-Sender: inefedor@gmail.com X-Host-Fingerprint: 209.85.215.54 mail-la0-f54.google.com Received: from [209.85.215.54] ([209.85.215.54:38103] helo=mail-la0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B9/8E-62407-EF4CDE45 for ; Wed, 25 Feb 2015 07:50:07 -0500 Received: by lamq1 with SMTP id q1so3602055lam.5 for ; Wed, 25 Feb 2015 04:50:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:to:subject:references:date:mime-version :content-transfer-encoding:from:message-id:in-reply-to:user-agent; bh=SceJhjchxr0mkBpodyCQ57KTHkCzbA+avJnuq/de6vw=; b=mL9F3JIFl/+5I/9PA3iahTIedSD8QvtxDPTI2mPLkSkKoFY08PTVICsQkNNnWmYp9+ 7oNbsp2q0TQnej1LUAH+X/zjiAxFElhSI4PqCfjs5qLATG4Ngm0MnRFndeREUVmG2y5r rwcGltTEkVvY+vmuoK86jdvZZfHW0oI/sIeoXmVmttNDcTfsC+G1NJCFi60Xzze8Muaq OmuY1VoFRZ/XImDT3LLNv3VDv2Zyg2nPyC7wSXlWv3Vj5L8oJqeRaM2shIUFfn6P6EFA JxDYtg6RADbIe9tR8je9s9K1IMNhTzp/D57wNnCqwh9n33+r5BBFv/+Rvr3tW4A2jGHk wB9Q== X-Received: by 10.112.140.74 with SMTP id re10mr2699893lbb.80.1424868602839; Wed, 25 Feb 2015 04:50:02 -0800 (PST) Received: from nikita-hp-elitebook-750-g1 (broadband-37-110-139-150.nationalcablenetworks.ru. [37.110.139.150]) by mx.google.com with ESMTPSA id en12sm5426512lbc.11.2015.02.25.04.50.01 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 25 Feb 2015 04:50:01 -0800 (PST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: internals@lists.php.net References: Date: Wed, 25 Feb 2015 15:48:50 +0400 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: User-Agent: Opera Mail/12.16 (Linux) Subject: Re: [PHP-DEV] Re: [RFC-Discuss] Scalar Type Declarations v0.5 From: inefedor@gmail.com ("Niktia Nefedov") On Wed, 25 Feb 2015 15:42:11 +0400, Niktia Nefedov wrote: > On Wed, 25 Feb 2015 16:30:32 +0400, Dmitry Stogov > wrote: > >> anyone may tell, what this will print without running :) >> >> main.php >> ======== >> > declare(strict_types=1) >> include "a.php"; >> include "b.php"; >> var_dump(foo("5")); >> ?> >> >> a.php >> ===== >> > declare(strict_types=0) >> function foo(string $a): string { >> bar($a); >> return $a; >> } >> ?> >> >> b.php >> ===== >> > declare(strict_types=1) >> function bar(int &$a) { >> var_dump($a); >> } >> ?> >> >> Thank. Dmitry. > > > Hi Dmitry, > > This will error out because $a in the scope of `foo` will be coerced to > int type when passed to bar by reference. > > References are a problem for weak-only types as well (even more so I > would say, because in a lot of cases they would continue working > truncated or changed). > > Happily there are not lots of post-php5 code that uses references here > and there, but that would be good to add the point about them to both > RFCs (and in documentation in future) just so that users would be aware > of that. Ah sorry I was too quick on judging, Florian is right, when foo returns its value it will be coerced back to string because of strict=0 in this case...