Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58100 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80944 invoked from network); 27 Feb 2012 00:09:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Feb 2012 00:09:49 -0000 Authentication-Results: pb1.pair.com smtp.mail=arvids.godjuks@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=arvids.godjuks@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.170 as permitted sender) X-PHP-List-Original-Sender: arvids.godjuks@gmail.com X-Host-Fingerprint: 209.85.212.170 mail-wi0-f170.google.com Received: from [209.85.212.170] ([209.85.212.170:41148] helo=mail-wi0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 56/66-40985-CC9CA4F4 for ; Sun, 26 Feb 2012 19:09:49 -0500 Received: by wibhm4 with SMTP id hm4so2880154wib.29 for ; Sun, 26 Feb 2012 16:09:45 -0800 (PST) Received-SPF: pass (google.com: domain of arvids.godjuks@gmail.com designates 10.180.95.105 as permitted sender) client-ip=10.180.95.105; Authentication-Results: mr.google.com; spf=pass (google.com: domain of arvids.godjuks@gmail.com designates 10.180.95.105 as permitted sender) smtp.mail=arvids.godjuks@gmail.com; dkim=pass header.i=arvids.godjuks@gmail.com Received: from mr.google.com ([10.180.95.105]) by 10.180.95.105 with SMTP id dj9mr22912351wib.18.1330301385433 (num_hops = 1); Sun, 26 Feb 2012 16:09:45 -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 :content-type; bh=yqITM8yyYGOvevI/LyV2P20nxiz+HvAmN2tH/98kDLk=; b=MwRLQh92JzLIt7K9AZAUb5HrZ1MKJFLDLxLalCptS6RlLnyFpDrxE50a9Btyw1UAZy 5opCkomMCu97PPXGGTUhD9oTxOjE4FmYWJ5ib9BBuTahr4/JypfmrSZJXfoDuV9CpVdE VvNeCf2DzaqX2eLnAyT0jG6wFV36BO3DeK65Y= MIME-Version: 1.0 Received: by 10.180.95.105 with SMTP id dj9mr18243077wib.18.1330301385247; Sun, 26 Feb 2012 16:09:45 -0800 (PST) Received: by 10.227.117.1 with HTTP; Sun, 26 Feb 2012 16:09:45 -0800 (PST) Received: by 10.227.117.1 with HTTP; Sun, 26 Feb 2012 16:09:45 -0800 (PST) In-Reply-To: References: <4F455C96.50706@gmail.com> <4F455E91.2060408@alliantinternet.com> <028001ccf1ab$0b200050$216000f0$@alliantinternet.com> <4F457517.7050901@alliantinternet.com> <028d01ccf230$91d79b00$b586d100$@alliantinternet.com> <4F4686C6.2040207@sugarcrm.com> <4F496818.8000405@sugarcrm.com> <4F4982BF.8090102@sugarcrm.com> Date: Mon, 27 Feb 2012 02:09:45 +0200 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=f46d0442816a830cc204b9e6ede8 Subject: Re: [PHP-DEV] [RFC] Enum proposal (yet another) From: arvids.godjuks@gmail.com (Arvids Godjuks) --f46d0442816a830cc204b9e6ede8 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I absolutely agree with this. The hurdle with the strict type hinting is pictured very well. Strict is strict - either the whole codebase follows it, or it doesn't follow it at all. If a part of the code uses it - means all the code comunicating with that part has to use, or at least has to be written with the strict type hinting in mind. Oh, and i remembered a case where strict type hinting would be highly questionable - the "mixed" variant. Right now we document thouse with the phpdoc comments, but its quite common use in php to accept a null or an array for example. I can't imagine strict type hinting in this case, but weak type hints can work. 27.02.2012 0:51 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0= =B5=D0=BB=D1=8C "John LeSueur" =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB: > [trim] > >> 2. "Strict type hinting would eliminate PHP's flexibility and take away >> its >> unique simplicity." >> >> I respectfully disagree. Again, let me remind you that we are *not* >> talking >> about *converting *PHP to strict type hinting. Instead, we're merely >> talking about allowing PHP developers to *choose* whether or not to make= a >> given function use dynamic or strict type hinting. The default behavior >> will remain dynamic, just as it is now. But there are situations where >> strict type hinting, even in a PHP script, would make more sense. There >> are many PHP developers, myself among them, who see considerable benefit >> in >> being able to make a function more condensed and streamlined without >> having >> to waste so much time on sanity checks that could instead be handled at = a >> lower level in the core. >> >> > So this is the argument that those who object to strict type hinting don'= t > agree with. Take the following: > > function strictTypes(/*int*/ $var) > { > //this is what the engine does if we have strict type checking > if(!is_int($var)) trigger_error(); > } > > function weakTypes(/*int*/ $var) > { > //this is what the engine does if we have weak type hinting, or > something similar. > if(!is_numeric($var) || (int)$var !=3D $var) trigger_error(); > else $var =3D (int)$var; > } > > function dynamicTypes($var) > { > strictTypes((int) $var); > //if $var is not an int, we just made it 0, and hid the type error. > //to avoid this mistake we have to do: > strictTypes(is_int($var) ? $var : ((is_numeric($var) && (int)$var =3D= =3D > $var) ? (int)$var : trigger_error()); > //or something like it. > weakTypes($var); > //we'll get an error if $var can't be converted to an int without dat= a > loss. > } > > By calling the strictTypes() function, the dynamicTypes() function > inherits the problem of validating the type of $var. Well, if I'm writing > the dynamicTypes function, I don't want that work, so I push it up the > chain, and change my dynamicTypes function to statically typed. If you're > into static types, then you say, that's great, someone should make sure > that $var has the right type when they got it from the user. But if you'r= e > not into static types, you were just forced to do type checking, either i= n > your code, or passing it up the call chain for someone else to do the typ= e > checking. That's what is meant when we say dynamic typing can't really > coexist with strict typing. For those into dynamic types, weak type hinti= ng > is much more palatable, because it doesn't require callers to adopt the > same philosophy. > > If you want type hinting, you'll have to specify which kind you want, > strict or weak. If it's strict type hinting, you'll need to convince even > those who think dynamic typing is a guiding principle of PHP that it can = be > done without forcing strict typing up the call chain. Weak type hinting i= s > a softer sell, but requires a lot of thought(much of which has been done, > if you look in previous discussions) , about how and when to convert valu= es. > --f46d0442816a830cc204b9e6ede8--