Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83803 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80962 invoked from network); 25 Feb 2015 15:49:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Feb 2015 15:49:46 -0000 Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.180 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.180 mail-vc0-f180.google.com Received: from [209.85.220.180] ([209.85.220.180:33385] helo=mail-vc0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E0/F7-62407-81FEDE45 for ; Wed, 25 Feb 2015 10:49:46 -0500 Received: by mail-vc0-f180.google.com with SMTP id im6so1630423vcb.11 for ; Wed, 25 Feb 2015 07:49:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=98FY109KupUQoQitCBaaBa2tHeoaZ5Oe3Kg6sViEpys=; b=ltNewErbjWSTvMNmbH1s2JhNlzH5paJhl7iuw7hDsqYRU18q4M8D+bzmJ8L/GobPTi Y+uLAPYS23euO2SuMbukNGQd87vgBoQGFI2p5KYWwU84YuAqaLlCMOcs8czMBaf3f/x9 Sr1hjMH+TMZIQYm3FxHSqWyR2dv/AHkGDUNYU9uiOdQDXd07+YBzgieLB9myHJshhj3r lNBUJ3qXRhL3NPh/LHW+e69icSZv9mSi7PA+lkh9Rfz2/QTdUtpu6BoIw6/iZhZpnkDh vy/E+fNEkL4nZna3PEeHdojZhHUUnVtUaL4eR6h2OWV5wOG0MJ6QE1YxMcBuOrDzq4wE iQcw== X-Gm-Message-State: ALoCoQmAXYt21fEbWGZBYsLtGctgH1ZfD3qkJCCu6rSHwRxL3EPqidG/8SuMGIn65qzz1uL/hMSf87dwxh+9/yNbf2ULBxgG2067va2bCdjSoaPgAx3X78h6vE4yCRMr4/p2GXY00pPShIWZ7z4T6x97eRX5ccXXyQ== MIME-Version: 1.0 X-Received: by 10.52.51.198 with SMTP id m6mr4580932vdo.38.1424879379176; Wed, 25 Feb 2015 07:49:39 -0800 (PST) Received: by 10.52.113.231 with HTTP; Wed, 25 Feb 2015 07:49:38 -0800 (PST) In-Reply-To: References: <7ef509ef10bb345c792f9d259c7a3fbb@mail.gmail.com> Date: Wed, 25 Feb 2015 19:49:38 +0400 Message-ID: To: Niktia Nefedov Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a1136a0ea3e770d050feb95ed Subject: Re: [PHP-DEV] Coercive Scalar Type Hints RFC From: dmitry@zend.com (Dmitry Stogov) --001a1136a0ea3e770d050feb95ed Content-Type: text/plain; charset=UTF-8 On Wed, Feb 25, 2015 at 5:23 PM, Niktia Nefedov wrote: > On Wed, 25 Feb 2015 17:54:21 +0400, Dmitry Stogov wrote: > >> The object on the call-site should remain to be an object (if it's not >> passed by reference), however the called function will receive a string. >> It works in PHP-5 and PHP-7. Nothing should be changed. >> $ sapi/cli/php -r 'class X {function __toString(){return "abc";}} $x=new >> X; var_dump(strlen($x)); var_dump($x);' >> int(3) >> object(X)#1 (0) { >> } >> However, declare(strict_types=1) will break this. see >> https://github.com/ircmaxell/php-src/compare/scalar_type_hints_v5#diff- >> ef5bf53d1412b50f85d125ca4fe84741R1182 >> Thanks. Dmitry. >> > > Dmitry, I was talking about passing an object to a function, expecting a > reference of a string: > > 'class X { function __toString() { return spl_object_hash($this); } } $x = > new X; function foo(string &$x){} foo($x); var_dump($x);' > > Now what would this produce in Coercive STH is still an open question I > guess as there is no implementation yet. > This will change $x because it's passed by reference. This is the common "problem" for all current proposals, because for parameters passed by reference we check only "input" types, and don't guarantee anything about output. int(321) ?> Thanks. Dmitry. --001a1136a0ea3e770d050feb95ed--