Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58302 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99515 invoked from network); 28 Feb 2012 23:02:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Feb 2012 23:02:50 -0000 Authentication-Results: pb1.pair.com header.from=dmgx.michael@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmgx.michael@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.54 as permitted sender) X-PHP-List-Original-Sender: dmgx.michael@gmail.com X-Host-Fingerprint: 74.125.82.54 mail-ww0-f54.google.com Received: from [74.125.82.54] ([74.125.82.54:52004] helo=mail-ww0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 63/9D-36673-91D5D4F4 for ; Tue, 28 Feb 2012 18:02:49 -0500 Received: by wgbdq13 with SMTP id dq13so1612190wgb.11 for ; Tue, 28 Feb 2012 15:02:46 -0800 (PST) Received-SPF: pass (google.com: domain of dmgx.michael@gmail.com designates 10.216.134.157 as permitted sender) client-ip=10.216.134.157; Authentication-Results: mr.google.com; spf=pass (google.com: domain of dmgx.michael@gmail.com designates 10.216.134.157 as permitted sender) smtp.mail=dmgx.michael@gmail.com; dkim=pass header.i=dmgx.michael@gmail.com Received: from mr.google.com ([10.216.134.157]) by 10.216.134.157 with SMTP id s29mr11066267wei.1.1330470166295 (num_hops = 1); Tue, 28 Feb 2012 15:02:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=EuPClVYWdJ3ohoarqTLlbOCDMoSl/7ckxn/MhMXSW/Q=; b=gtTTTS0Pq0cV9DvQoS//YgWP2BUaCQglj3FnTnDf9PSoYYITH+O0Q9WR7WdwSSfZu2 7Vb5IAMurO0TuQG9c+NGS0rwnQLGdcCIKbRgkVJiaHeElKHf28RAdVR/a2EHhSgs2YXf hBp7BB+39Y0BsMvCa4vrYSWXzfSc/UgZ7vCvU= MIME-Version: 1.0 Received: by 10.216.134.157 with SMTP id s29mr8833419wei.1.1330470165183; Tue, 28 Feb 2012 15:02:45 -0800 (PST) Received: by 10.216.30.149 with HTTP; Tue, 28 Feb 2012 15:02:44 -0800 (PST) In-Reply-To: References: <1330357150.2159.30.camel@guybrush> <4F4C1324.2040905@gmail.com> Date: Tue, 28 Feb 2012 18:02:44 -0500 Message-ID: To: Arvids Godjuks Cc: Simon Schick , internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Scalar type hinting From: dmgx.michael@gmail.com (Michael Morris) Much of what you put forward here is why I don't want there to be a weak/strong divide. We can do "weak". Strong not so much. Current syntax allows $a =3D (int) 3; echo gettype($a); // integer $a =3D 'Hello'; echo gettype($a); // string. Under the new syntax this happens. int $a =3D 3; echo gettype($a); // integer $a =3D 'Hello'; E_WARNING raised echo gettype($a); // integer In other words, once the variable's type is declared, it WILL NOT CHANGE. If one doesn't want that behavior, don't declare a type, and things will work as they always have. On Tue, Feb 28, 2012 at 5:56 PM, Arvids Godjuks wrote: > Hi, Simon. > > Actually I also advocated for notices/warnings on conversion with data lo= ss. > What just has to be done - the rule table when notices/warnings are throw= n. > > What I have in mind is no variable type hinting at all. What I want to > see is function/method type hinting. > And, because the zval actually has type in it, you actually already > weakly type hint the variable anyway: > > $a =3D 1; > echo gettype($a); // integer > > $a =3D (int)"1"; > echo gettype($a); // integer > > $a =3D (string)1; > echo gettype($a); // string > > And so on. This part is in the language, just has different syntax. > > So no-no-no from me on this: > int $a =3D 1; > int $a =3D "1"; > > It just duplicates the functionality. And I don't like the strict int > $a =3D 1; I have already explained why it's not a good idea from the > technical standpoint. > > So what I want is this: > > function int test(int $a, int $b) > { > =C2=A0 =C2=A0return $a * $b; > } > test(1, 2); // 2; > test("1", 2); // 2 > test("1aaa", 2); // E_NOTICE or E_TYPE and result 2 > test(array(2), 2); // E_RECOVERABLE_ERROR - just like with array type hin= t now. > > It's really what the most people want. Simple, easy to pick up (object > and array already have this) and is just optional. > > I purpose to deal with this and when it works and is released to the > wild then see if more strictness even is needed. I think this simple > weak type hinted functionality will suffice. > > ---------- Forwarded message ---------- > From: Simon Schick > Date: 2012/2/28 > Subject: Re: [PHP-DEV] Scalar type hinting > To: Arvids Godjuks > =D0=9A=D0=BE=D0=BF=D0=B8=D1=8F: Michael Morris , = internals@lists.php.net > > > Hi, Arvids > > I do understand your arguments ... > > For me personally it's mostly to separate between string and numbers. > A string to number transformation is most-likely not without loosing > something ... This is most likely the reason why I want to have a > E_STRICT or E_NOTICE if something like that happens. Same appears to a > transformation of a number to Boolean. > I don't really care how variables are handled in the very inner part > of the php-core as long as it's effective ;) > > As you're talking about serialization ... that's right ... If you're > serializing an array containing strict variables would require a > change. > Here you'll have a big downwards-compatibility-break ... > > We can do this discussion endless ... but I think you got the point > why I want something like this. > Until now I trusted my IDE (PhpStorm) that's reading the PhpDoc of a > function and marking it as warning if I try to put in an integer > whereas the documentation says that this function expects a string (or > an error if it should be an object or array). > > Bye > Simon