Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75615 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64728 invoked from network); 16 Jul 2014 23:32:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jul 2014 23:32:55 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.200 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.200 imap1-2.ox.privateemail.com Received: from [192.64.116.200] ([192.64.116.200:47263] helo=imap1-2.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AF/F4-37298-4AB07C35 for ; Wed, 16 Jul 2014 19:32:54 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 33300B00087; Wed, 16 Jul 2014 19:32:50 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at imap1.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap1.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 4Gr0jbGVQq_b; Wed, 16 Jul 2014 19:32:49 -0400 (EDT) Received: from [192.168.0.15] (unknown [90.210.122.167]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 1E84CB0007B; Wed, 16 Jul 2014 19:32:46 -0400 (EDT) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) In-Reply-To: <53C706D7.3010200@sugarcrm.com> Date: Thu, 17 Jul 2014 00:32:43 +0100 Cc: Zeev Suraski , Rowan Collins , "internals@lists.php.net" Content-Transfer-Encoding: quoted-printable Message-ID: References: <08503591-EFC8-48E6-984E-FFC292C5EA5F@ajf.me> <16D48604-0C0A-4613-91A4-21392E3A2636@ajf.me> <05CE2216-C5D9-4937-9F2E-AA1407284D9F@ajf.me> <53C460DF.5040304@sugarcrm.com> <53C53A96.2040303@gmail.com> <53C55342.1010207@sugarcrm.com> <53C563B3.6060905@gmail.com> <54536191-1B92-4933-973F-0C8289D13A4C@ajf.me> <00d12255efc53466245b21a83ff7d474@mail.gmail.com> <53C652FA.6010704@gmail.com> <53C66D6E.9060200@gmail.com> <60f496756412de6ad97751d91ead5058@mail.gmail.com> <53C706D7.3010200@sugarcrm.com> To: Stas Malyshev X-Mailer: Apple Mail (2.1878.6) Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) From: ajf@ajf.me (Andrea Faulds) On 17 Jul 2014, at 00:12, Stas Malyshev wrote: > I think if the compromise is having multiple set of rules for implicit > casts then this compromise is not worth it. If you answer to the > question of "what happens if I use a string in boolean context" with > "well, it depends, if it's boolean context in syntax construct, it's = one > rule, if it's internal function, another, if it's user function, yet > another" - it's not a good compromise. Any solution where you can give > an actual answer like "empty string is false, all others are true" is > much better. I'm not a fan of strict types in PHP, but having > inconsistent rules is IMO so bad that even strict types would be = better. > At least you'd then know on which planet you are. To be fair, the RFC as it stands has booleans be strict, with true and = false the only allowed values. Also, strings, integers and floats have = (IMO) easy-to-explain rules under this RFC.: * bools: bools and objects that convert to bools only * strings: Anything that can be losslessly converted to a string works = (any int, float, string, or object with toString) * float: Anything that can be losslessly converted to a float (any int, = float, numeric-only string, or object that converts to float) * int: Anything that can be losslessly converted to an int (any int, = float that=92s integral, integral numeric-only string, or object that = converts to int) Actually, objects are a special case here, unfortunately, but I didn=92t = really have a choice because they cast weirdly. This compares to the current zpp rules (as well as I can remember them, = anyway): * bools: Any int, string, float, bool, or object that can cast to bool; = if it=92s an int, then non-zero is true; if it=92s a float, then = non-zero is true; if it=92s a string, then it=92s true unless it=92s an = empty string or zero * strings: Anything, unless it=92s an object that doesn=92t implement = toString (I think that=92s the rule, anyway) * int: Any int, float, bool, object that casts to int, or string that = begins with numeric digits (this is sometimes a notice) * float: Any int, float, bool, object that casts to float, or string = that begins with float-like digits (this is sometimes a notice) However, I honestly can=92t remember zpp=92s exact behaviour and I might = have made some mistakes there. Is zend_parse_parameters=92s behaviour actually documented in the = manual? A quick search finds nothing. -- Andrea Faulds http://ajf.me/