Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84571 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92999 invoked from network); 11 Mar 2015 18:53:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Mar 2015 18:53:30 -0000 Authentication-Results: pb1.pair.com header.from=zeev@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=zeev@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.212.176 as permitted sender) X-PHP-List-Original-Sender: zeev@zend.com X-Host-Fingerprint: 209.85.212.176 mail-wi0-f176.google.com Received: from [209.85.212.176] ([209.85.212.176:37634] helo=mail-wi0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6B/EF-07702-82F80055 for ; Wed, 11 Mar 2015 13:53:29 -0500 Received: by widem10 with SMTP id em10so26882869wid.2 for ; Wed, 11 Mar 2015 11:53:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:references:in-reply-to:mime-version :thread-index:date:message-id:subject:to:cc:content-type; bh=kaB/imA3wO58O0Z83nzyJmmlCDrd/GFhWIBvKf/dNL0=; b=YA3D284W1wjeniEfgLGuQuNH4s7nZRstdU3GU63KmTy9mKveFyiOPRYBuVJVW6TMKm Ka7AjZZEnEwu+fZSshX0aqfJymzlU97W7xFXLlvbk8XKt4Y59zbUV46fu6erJm8yBiuw c9Ui1eg34sUyiAYc3+08HHDBcWY8TlRHJ7Qzn7IwhTDz1DPsQKdyuwCbcq/kyUDAbBYb kiaQx8nKOWM73ginTozPAchAn9EGEggXjy1NhuYRTKAzfIWCyTW0GOuxM2W+QLxcLkPr Jfq272ij4/WBKBOZuswagJK7R5uQU3toIcsESUZ+DF3ekBN97iI1L7NHdqnToRQO/lxa IjVw== X-Gm-Message-State: ALoCoQn2pVCQGGMXr90aw659uc1rS7Wm6MZiGMoF8sjIZcBjq190I2SMZnSUGRYejJUmbt5pEJ+XjIfF0M0skPVGs8/ijS2lfTLKk3Q3YvlSlJvPf2Aiyrj1mwHEFTqI4hIwOo3/+gCbjZGBfGAlb9Lfqj52ZNeeaw== X-Received: by 10.181.11.202 with SMTP id ek10mr45229769wid.37.1426100004844; Wed, 11 Mar 2015 11:53:24 -0700 (PDT) References: <76c47c6fbd961958c10bc1a069377a34@mail.gmail.com> In-Reply-To: MIME-Version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQD1YWXqQx6MzBD1VX0WwX4EEwdHWAHgk7pSAio5GUyerT7xcA== Date: Wed, 11 Mar 2015 20:53:24 +0200 Message-ID: <2d48b241e682e59df6ab876b42663628@mail.gmail.com> To: Anthony Ferrara Cc: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Subject: RE: [PHP-DEV] RE: [VOTE][RFC] Coercive Scalar Type Hints From: zeev@zend.com (Zeev Suraski) > -----Original Message----- > From: Anthony Ferrara [mailto:ircmaxell@gmail.com] > Sent: Wednesday, March 11, 2015 8:28 PM > To: Zeev Suraski > Cc: Theodore Brown; internals@lists.php.net > Subject: Re: [PHP-DEV] RE: [VOTE][RFC] Coercive Scalar Type Hints > > Zeev, > > >> You also stated above that false->bool is not supported (I'm guessing > > you > >> meant float->bool). So users would be able to pass "4.3" to a bool > > typehint, > >> but not 4.3? This behavior seems very arbitrary and confusing. > > > > It may be confusing, but only academically so. Again, this approach > > tries to work well with real world usage - and reject conversions > > which are likely to be erroneous. "4.3" may look like a floating > > point number but in the context of conversion to boolean, that doesn't > > matter much. It's a string. > > Doesn't that contradict what you've been saying the whole time about how > "13" and 13 and 13.0 are really "the same thing", and as such should be > coerced? No, it does not. "13" and 13 and 13.0 are the same thing when you're expecting an integer, and rejecting "13" as an integer is nothing but noise in the vast majority of cases - noise that will push towards an explicit cast. Strings, however, are treated in a totally different way that places zero meaning on their numeric value across the entirety of PHP when in the context of a boolean. > > > function bar(float $x) > > $foo = 1; > > bar($foo); // will definitely fail in strict mode > > No, actually it won't fail in strict mode: > https://wiki.php.net/rfc/scalar_type_hints_v5#integers_should_be_accepted > _for_strict_float_arguments You're right, sorry. Reverse it then: function bar(int $x) $foo = 1.0; bar($foo); // will definitely fail in strict mode Zeev