Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83805 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86437 invoked from network); 25 Feb 2015 16:01:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Feb 2015 16:01:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=pierre.php@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pierre.php@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.175 as permitted sender) X-PHP-List-Original-Sender: pierre.php@gmail.com X-Host-Fingerprint: 209.85.216.175 mail-qc0-f175.google.com Received: from [209.85.216.175] ([209.85.216.175:35140] helo=mail-qc0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 51/00-20665-FD1FDE45 for ; Wed, 25 Feb 2015 11:01:37 -0500 Received: by qcyl6 with SMTP id l6so3674764qcy.2 for ; Wed, 25 Feb 2015 08:01:32 -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=P+nqIgdgovYxBTCHuhCf4yVOdvijMmOFhfx9iDxSlTI=; b=JrKxgZXm0pQ7F5nr01Clnfz9Qg0REW+y9yN6jY6LlZSFrTeUiL8wr0LE32OmGnf3aT NSd98rUxV9nIxOJ5Jdwv00yKcmvy/WUQanz/Dh6oRS8fqFGksm7zTd8U139yEkwr2MaH dTNcfema4zFZheIuzjXSyQEtNoKvODfbXAgA+h/YhIB6OIcICwaLrOFWGV5n0imMUqyW ynNPY4Eiv/+CVK7mqCLptqht4csEfUamDyyFezyRPtSsy8/c8IvWeX2e3jYZUHRqeDvJ 4ODwCk797ydF8B7IKTPT8OyejLD9p1dl7Abd6l0S42s8xmIqD32bcyelneHunEw0a9eE xNcQ== MIME-Version: 1.0 X-Received: by 10.140.238.13 with SMTP id j13mr8268545qhc.75.1424880092195; Wed, 25 Feb 2015 08:01:32 -0800 (PST) Received: by 10.96.39.195 with HTTP; Wed, 25 Feb 2015 08:01:31 -0800 (PST) In-Reply-To: References: Date: Wed, 25 Feb 2015 08:01:31 -0800 Message-ID: To: Dmitry Stogov Cc: Anthony Ferrara , Niktia Nefedov , PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Re: [RFC-Discuss] Scalar Type Declarations v0.5 From: pierre.php@gmail.com (Pierre Joye) On Wed, Feb 25, 2015 at 7:29 AM, Dmitry Stogov wrote: > On Wed, Feb 25, 2015 at 6:09 PM, Anthony Ferrara > wrote: > >> 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. >> > > OK. it's a BC break. > What is the reason for __toString() if it's not going to be called. > > >> >> 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)). >> > > this is about conversion rules that may be safe or not. > > >> 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. >> > > turn off magic to get what? Need to write explicit (int) or (string)? > We have a number of such patterns that hide errors even in PHP sources (in > C). Right, we do. And we should somehow treat warnings like that as error, in C :) That being said (and totally OT), changing casting rules and adding yet another set of magic rules is better? I agree to totally disagree here. I will never agree on changing these rules (or maybe in php12). Cheers, -- Pierre @pierrejoye | http://www.libgd.org