Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83783 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43459 invoked from network); 25 Feb 2015 13:16:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Feb 2015 13:16:16 -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.217.178 as permitted sender) X-PHP-List-Original-Sender: inefedor@gmail.com X-Host-Fingerprint: 209.85.217.178 mail-lb0-f178.google.com Received: from [209.85.217.178] ([209.85.217.178:46228] helo=mail-lb0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9E/A0-62407-F1BCDE45 for ; Wed, 25 Feb 2015 08:16:16 -0500 Received: by lbjf15 with SMTP id f15so3648748lbj.13 for ; Wed, 25 Feb 2015 05:16:12 -0800 (PST) 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:from :message-id:in-reply-to:user-agent; bh=oKtZxYI5nnFDVf/djz/s/SHA1BIUW+MzzXQzRO7M4YU=; b=JctCMIhJgERkgCw0rjZtx8dew4pGwBsymUQlHtD2LQNsXyEJilVfXgqbfM1M9XnqXd K1n1bcnyLb3nSZ0Uwd5UnWMAYbf1un9rMHiM+ixB4Qefj6RRj56yEQC5snWholkXG0XM fNbDAfvGYg7ntBrB/Z/V0Knq+lFZyKRcBsHUfPBiSzbKg1IbeHXpX0pJUGJkfRXdefbm qDqIpwvKplUklfImMwqdfHglc/XQ+THih6nU/UDqeLIAIsC9jBumSl4tydKQRzlKqFA/ VQRHijyWaQ648yFD0k4KMuGIHcfGLIlP4Qc6xhzjhFKU8UEuqWpZEiQCnABO8dsZiXYf GQbQ== X-Received: by 10.152.10.66 with SMTP id g2mr2780742lab.44.1424870172301; Wed, 25 Feb 2015 05:16:12 -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 n12sm7696479lbg.31.2015.02.25.05.16.10 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 25 Feb 2015 05:16:11 -0800 (PST) Content-Type: multipart/alternative; boundary=----------WxPwHEYQ9UiaReDK7W8nbf To: "Dmitry Stogov" Cc: "PHP Internals" References: Date: Wed, 25 Feb 2015 16:15:00 +0400 MIME-Version: 1.0 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") ------------WxPwHEYQ9UiaReDK7W8nbf Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit On Wed, 25 Feb 2015 16:55:57 +0400, Dmitry Stogov wrote: > > > On Wed, Feb 25, 2015 at 2:42 PM, 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. > > I think it'll work without errors and produce some explainable but weird > output. I didn't run it myself yet. Yep, you're right. But it's not a problem of mixed-mode, it's more of a problem of introducing coercive type hints at all, honestly... I wonder what Zeev plans to do with __toString coercion in his RFC, because that is even more severe problem when your object unnoticedly becomes a string. ------------WxPwHEYQ9UiaReDK7W8nbf Content-Type: multipart/related; boundary=----------WxPwHEYQ9UiaRe1tDuzsvJ ------------WxPwHEYQ9UiaRe1tDuzsvJ Content-Type: text/html; charset=utf-8 Content-ID: Content-Transfer-Encoding: Quoted-Printable On Wed, 25 Feb 2015 16:55:57 +0400, Dmitry Stogov <dmitry@zend.= com> wrote:



On Wed, Feb 25, 2015 at= 2:42 PM, Niktia Nefedov <inefedor@gmail.com> wrote:<= br>
=
On Wed, 25 Feb 2015 16:30:32 +0400, Dmitry Stogov <= dmitry@zend.com= > wrote:

anyone may tell, what this will print without running :)

main.php
=3D=3D=3D=3D=3D=3D=3D=3D
<?php
declare(strict_types=3D1)
include "a.php";
include "b.php";
var_dump(foo("5"));
?>

a.php
=3D=3D=3D=3D=3D
<?php
declare(strict_types=3D0)
function foo(string $a): string {
    bar($a);
    return $a;
}
?>

b.php
=3D=3D=3D=3D=3D
<?php
declare(strict_types=3D1)
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.

= I think it'll work without errors and produce some explainable but weird= output. I didn't run it myself yet.

Yep, you're right. But it's not a problem of = mixed-mode, it's more of a problem of introducing coercive type hints at= all, honestly... I wonder what Zeev plans to do with __toString coercio= n in his RFC, because that is even more severe problem when your object = unnoticedly becomes a string.
------------WxPwHEYQ9UiaRe1tDuzsvJ-- ------------WxPwHEYQ9UiaReDK7W8nbf--