Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58761 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69473 invoked from network); 8 Mar 2012 00:54:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Mar 2012 00:54:50 -0000 Authentication-Results: pb1.pair.com header.from=simonsimcity@googlemail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=simonsimcity@googlemail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.214.170 as permitted sender) X-PHP-List-Original-Sender: simonsimcity@googlemail.com X-Host-Fingerprint: 209.85.214.170 mail-tul01m020-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:35316] helo=mail-tul01m020-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 44/8E-15180-453085F4 for ; Wed, 07 Mar 2012 19:54:48 -0500 Received: by obbwd1 with SMTP id wd1so8678731obb.29 for ; Wed, 07 Mar 2012 16:54:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=xUlgZd4lxZB9KCtkj6inShCz6DikTeAqrcYqUYCLvp8=; b=UUIU6DoVYrlHtnw8Y3f85lSovIhv6qcpKkWRAVsFiHpryUO+UOCXkfAgdg7nUmDfHS Z68OdNi/QoXBLb5JMEvQXWeHkUtS8ti55bdjxe80LMWktWxmHXsJElmkD+S8mawVVA7C 4mCJk7IBPI2mtbaTkriPzbwfqvxKF1U7daHGsG4m+MDsgkXNaKT+J83gRAYfAY+DsInJ 5fwH76wpKcZ7MnMKp2O6tsuR3cq6huMXNDg2DNshLlpTGahv0U8r+aSLOBkCSlUbyAHD dx0MDYYeqVj8MnWV9ZhxCdZoojwAhJAmsrDhxTxMFbRIW6zXS3L2RrTat3VoeKS07MEz dDVw== MIME-Version: 1.0 Received: by 10.182.183.40 with SMTP id ej8mr335938obc.41.1331168082176; Wed, 07 Mar 2012 16:54:42 -0800 (PST) Received: by 10.60.63.70 with HTTP; Wed, 7 Mar 2012 16:54:42 -0800 (PST) In-Reply-To: References: <52.38.15021.3A1E65F4@pb1.pair.com> <4F570EBB.6030103@sugarcrm.com> <60744d7ea642fe03c7110502a3f4276a@mohiva.com> Date: Thu, 8 Mar 2012 01:54:42 +0100 Message-ID: To: Arvids Godjuks Cc: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Scalar Type Hinting From: simonsimcity@googlemail.com (Simon Schick) Hi, Just a small addition to what I wrote about handling null ... function foo(array $d =3D array()) { var_dump($d); } foo(null); // This fails with the message: Argument 1 passed to foo() must be an array, null given As this code fails I'd not expect to change this behavior for the weak-type= s. function foo(int $d =3D 20) { var_dump($d); } foo(null); // This should then also fail. Don't care about what's the default-value. Bye Simon 2012/3/8 Simon Schick : > Hi Arvids, > > I pretty much like this idea as it's more strict. Let me say something > to the questions you pointed out here. > > 2012/3/7 Arvids Godjuks : >> I realize that with scalars it's not that straight forward, but >> complicating things by adding an auto-cast syntax and so on is just >> ridiculous. Hints should stay, well, hints. The only problem we have >> is complications of accepting numerical strings or numbers as strings. >> And what to do with "null". > > I'd like to handle it the same way as it's handled with the classes > right now. If null is not the default-value you'll get an error when > you pass null in there. > One thing I'd like opened here: If you define a default-value > different than null, should you be able to pass null as well and the > compiler will use the default-value? > >> function a(bool $bool) {} >> a(10); // Kill your self against the wall - write a(true); >> If you define bool - use the damn bool! > > I like that. What should we do if this appears? As it's now - just > throw an "Catchable fatal error" and let the script blow-up? I would > go this far. > >> >> I consider interchangeable only three cases: >> 1. Numerical string. >> 2. Integers and floats as strings. >> 3. Integer and string =C2=A00 1 as bool. >> >> Any other cases should error out. > > Until now I thought about the weak variable-types as a order ... > string, float, integer, Boolean. > All Boolean values are compatible be an integer (0 or 1) and all > integer are compatible to a float and so on. Do you think it's good to > have it this way? This would mean that you could also get a Boolean > true as string "1" ... I personally don't like that ... but I don't > know where to draw the strict-line. > Now think about that backwards. Can a "1" be passed as a parameter > that expects Boolean? If yes, I'd keep it consistent in both ways. > > Bye > Simon