Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80032 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68158 invoked from network); 31 Dec 2014 21:28:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Dec 2014 21:28:57 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.207 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.207 imap2-2.ox.privateemail.com Received: from [192.64.116.207] ([192.64.116.207:51840] helo=imap2-2.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FF/41-60454-89A64A45 for ; Wed, 31 Dec 2014 16:28:56 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id DA95E8C0081; Wed, 31 Dec 2014 16:28:53 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap2.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap2.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id qfxFzXpQDsEo; Wed, 31 Dec 2014 16:28:53 -0500 (EST) Received: from [192.168.0.13] (unknown [94.13.96.117]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id EE3F88C007D; Wed, 31 Dec 2014 16:28:52 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.1 \(1993\)) In-Reply-To: <54A466CB.9020400@gmail.com> Date: Wed, 31 Dec 2014 21:28:20 +0000 Cc: PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: References: <41D5BB0B-73AF-488E-968D-90B2878E3178@ajf.me> <54A466CB.9020400@gmail.com> To: Stanislav Malyshev X-Mailer: Apple Mail (2.1993) Subject: Re: [PHP-DEV] [RFC] Scalar Type Hints From: ajf@ajf.me (Andrea Faulds) Hey Stas, > On 31 Dec 2014, at 21:12, Stanislav Malyshev = wrote: >=20 > I like it, it's consistent and to the point. If we must have scalar > typed parameters (I'm not sure but if we do), IMO that's the way to do = it. Glad you like it. > The issue is the class names though. E.g. see: > = https://github.com/ralphschindler/zf2-db/blob/master/research/ColumnType/I= nteger.php >=20 > and: >=20 > = https://github.com/canaydogan/ObjectValidator/blob/master/src/ObjectValida= tor/Validator/Int.php >=20 > These are uppercase "I", but class names are not case-sensitive... So > we'll need to figure it out. Unfortunately, looking at github, > disallowing "class Int" looks like pretty bad idea. We can make it > lowercase-only, but this would be a bit weird since it's not sensitive > in all other places (unless we change that which is another huge can = of > worms). Yeah, it=E2=80=99s a problem. I think some breakage here is inevitable, = unfortunately. Some of the classes with these names are stand-ins for = scalar type hints, so that code can =E2=80=9Cjust=E2=80=9D migrate to = using actual hints. But this doesn=E2=80=99t apply to all of them. We could choose to simply not prohibit them as class names, but that = creates a weird inconsistency where you can make =E2=80=98class = Integer=E2=80=99 yet =E2=80=98function foo(Integer $a)=E2=80=99 hints = against the integer type, not your class. Type hints are very widely = used, so I doubt this would help anyone, and we=E2=80=99d still be = breaking existing code type hinting against such classes. There=E2=80=99s not much we can do really. I suppose there is one = positive outcome, in that hopefully when broken code is updated to work, = it might have more descriptive class names. :) > BTW, right now this code: >=20 > function foo(integer $a) { var_dump($a); } > foo(1); >=20 > produces this message: >=20 > Catchable fatal error: Argument 1 passed to foo() must be an instance = of > integer, integer given >=20 > which is pretty confusing I'd say :) We'd probably want to rephrase = that > message (yes, I know, patching all those tests yet again=E2=80=A6) We could rephrase it, but I don=E2=80=99t think it=E2=80=99s that bad. = Once scalar hints are in, you won=E2=80=99t get that error any more. I = think it could be worse as errors go, at least it distinguishes = semi-clearly between objects (=E2=80=9Cinstance of integer=E2=80=9D) and = other types (=E2=80=9Cinteger=E2=80=9D). Thanks! -- Andrea Faulds http://ajf.me/