Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58759 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67635 invoked from network); 8 Mar 2012 00:41:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Mar 2012 00:41:44 -0000 Authentication-Results: pb1.pair.com smtp.mail=simonsimcity@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=simonsimcity@googlemail.com; 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:39498] helo=mail-tul01m020-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 33/3E-15180-740085F4 for ; Wed, 07 Mar 2012 19:41:43 -0500 Received: by obbwd1 with SMTP id wd1so8663307obb.29 for ; Wed, 07 Mar 2012 16:41:40 -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=AhgX7+PMhfaW3KI7RQPYD9auC5ZxxSt9semtXGmvuIo=; b=eZy4mh6Q3INiJQMEal6GO8v1YTwrJ4/KUl4NEeMlc9xEf4idmmCjrtVLaUrJWI/wDK ZgLi+IzAtgMMH+RpzzHA8lprQ4/E8dYgQIa21rJsWW4mW9nX0zInSJPP/eD3+SdqEBtW Qn+YoyHxLPEg/GBh7jvn+Oltfc48AY2s743nNcjnwTOlzif3lPEwTXdb89PbgLoFC/dd RB97L2RxhLHOl0BJ+v+Frtm6+1hU5+14MTDd+kZ1wGvvz7azbL9FTtfeYVg8/DmcJxhO H9LJr7EXJY9/WCC9Qis6Fk7SieFXBtuUuWX41Sqh5NN00/zr3Vp5/PhdArzW6HRQW7Hu aNHA== MIME-Version: 1.0 Received: by 10.60.13.1 with SMTP id d1mr1662871oec.41.1331167300055; Wed, 07 Mar 2012 16:41:40 -0800 (PST) Received: by 10.60.63.70 with HTTP; Wed, 7 Mar 2012 16:41:39 -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:41:39 +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 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