Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83799 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74067 invoked from network); 25 Feb 2015 15:29:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Feb 2015 15:29:30 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.181 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.181 mail-vc0-f181.google.com Received: from [209.85.220.181] ([209.85.220.181:35004] helo=mail-vc0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F0/96-62407-95AEDE45 for ; Wed, 25 Feb 2015 10:29:30 -0500 Received: by mail-vc0-f181.google.com with SMTP id im6so1572818vcb.12 for ; Wed, 25 Feb 2015 07:29:27 -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=ntN0Fmybd2hoLfmYQntvYB+p2o2d2CHO/P0pkpL+UNc=; b=Pm5csGK7uChOOFKroii/8LEANUqBtlB1Xru+prok2tw+lx0N4KEDMw2jmFpqxixeR3 uXmK+wqI1xl+5d0HZ7rH2o/BnBVgDxXfV9n3Mvu25JEA2dr8s7i/2XyZfbE8MQMeF9oX SurdSYdjcepejtCBjxRH/vHe7ZX2ttLZvBxSFZaZmZD/Go9Vp35DoRiiJ2THBD4HJ/Wr GY4F6EILeIhRTe3dL6zWWADwTuikAuzOSq2uATc/Yhk/lXGY7QknqSapTPpRwNhhdDcg 5v1q9bj0ag2sypGuH5yQX8HvjHnvrJ8AgXuOXzFeDSCsbPI1Ipc3by5yxRHn884D8lXP tPbw== X-Gm-Message-State: ALoCoQlTabr8BhbPVbtd3PARhHkb38kbJGsMxlUGLjhCKgai0gz6dQ2H9zx8+FLJtVyW/TdiuL6JVFDWqXRQTNMi7tpmqSvYKmW+6cYrrpxJktZNqyouxocQ9V+qbN8nHJmZ49+YhaWy282rh257C1lIsty5DyXAlw== MIME-Version: 1.0 X-Received: by 10.52.99.230 with SMTP id et6mr4380981vdb.65.1424878166871; Wed, 25 Feb 2015 07:29:26 -0800 (PST) Received: by 10.52.113.231 with HTTP; Wed, 25 Feb 2015 07:29:26 -0800 (PST) In-Reply-To: References: Date: Wed, 25 Feb 2015 19:29:26 +0400 Message-ID: To: Anthony Ferrara Cc: Niktia Nefedov , PHP Internals Content-Type: multipart/alternative; boundary=20cf3071c7c0fc2b91050feb4ca1 Subject: Re: [PHP-DEV] Re: [RFC-Discuss] Scalar Type Declarations v0.5 From: dmitry@zend.com (Dmitry Stogov) --20cf3071c7c0fc2b91050feb4ca1 Content-Type: text/plain; charset=UTF-8 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). Thanks. Dmitry. > And it's fully opt-in, so there's nothing to "break". It's entirely > new behavior. Anthony > --20cf3071c7c0fc2b91050feb4ca1--