Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83792 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 63063 invoked from network); 25 Feb 2015 15:09:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Feb 2015 15:09:13 -0000 Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.169 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.217.169 mail-lb0-f169.google.com Received: from [209.85.217.169] ([209.85.217.169:45028] helo=mail-lb0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D8/24-62407-895EDE45 for ; Wed, 25 Feb 2015 10:09:12 -0500 Received: by lbiz12 with SMTP id z12so4391494lbi.11 for ; Wed, 25 Feb 2015 07:09:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=N4/xv3cih4PAGnyG91p+Xns9Y+NnyLnl4njJ/fYD3ZI=; b=f7ZearoKbv7sWfQzWKRG7BaQoiv9+fzOvRzhRtsXZAByufSX17oCm+dszTjZCFe4y3 J4j1mAe7yhGVUIeOwAFZKisrS4Pd/tEDU5FoPN9PIczHZukATUzLSrGrs9VQTS2qFYW7 te8un/v3zbNFz58kUDdIoNciAmUTQWyP+V1d7p0bXs2awz1NADaNfOcWIzGBQ5zR1Gah n5qMIqC6jpoTErsKkaegp7/zYKMgLAKGk4bJAqJjqR/IocvAfaIQ0WeinSD2WjzNU5CV HXOtIXLjjudqKWh1mvtc5Ol1VinjqP84fghXo3C5Nc4LZR/GdAQSgmyZv6FYHIuEtTnZ /RBA== MIME-Version: 1.0 X-Received: by 10.153.5.11 with SMTP id ci11mr2982672lad.95.1424876949279; Wed, 25 Feb 2015 07:09:09 -0800 (PST) Received: by 10.25.43.9 with HTTP; Wed, 25 Feb 2015 07:09:09 -0800 (PST) In-Reply-To: References: Date: Wed, 25 Feb 2015 10:09:09 -0500 Message-ID: To: Dmitry Stogov Cc: Niktia Nefedov , PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Re: [RFC-Discuss] Scalar Type Declarations v0.5 From: ircmaxell@gmail.com (Anthony Ferrara) Dmitry, > 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 "Break" is a loaded term. It's intentionally not calling __toString, because that's not only a cast (like "5" -> int(5)), but it's a lossy cast (like 5.5 -> int(5) or "5 apples" => int(5)). One point of strict mode is that it's there intentionally to turn off magic. It's there to make things explicit, predictable and robust. And it's fully opt-in, so there's nothing to "break". It's entirely new behavior. Anthony