Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83221 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84079 invoked from network); 19 Feb 2015 16:36:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Feb 2015 16:36:35 -0000 Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.173 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 74.125.82.173 mail-we0-f173.google.com Received: from [74.125.82.173] ([74.125.82.173:44033] helo=mail-we0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B7/03-18870-21116E45 for ; Thu, 19 Feb 2015 11:36:35 -0500 Received: by wesk11 with SMTP id k11so770746wes.11 for ; Thu, 19 Feb 2015 08:36:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=u+c/BC/6zhUOidP08MBr1sSGP6JutmubfdIp7EQ4o6A=; b=ETCFP27JGTNPs9+k4QZ+dNuzfgAbrLAr3/AUUqbYe4LhzKQon9TM1Uzab0f2+6u3Qj UhYbb+31UdGWtj240LdgQn7QsPW9wOyhVgJF5IwDjurTLWGdqXpiJ0NaPIhkr3r1ng5q hytvCsH0u5e15MCZ93lJ/vIIie8SNDyYYjRE9ujbTfFBGIRbsgSd3Pe85zTmYzIKiKdj KoeXZuX8ahaQgdomd+hFglzGNj7SddX1YFLvsszB1LWrqy5SrOYi2782zZ/z5AjdLGQk V4dlw4hqWXL5bMXaTbEnYLmxPlX0Fmo8m+bAOgHj+cOKL00+p3Je3Zcnkia4CaRRrmHZ 8OOw== X-Received: by 10.180.198.37 with SMTP id iz5mr11212990wic.95.1424363791124; Thu, 19 Feb 2015 08:36:31 -0800 (PST) Received: from Stas-Air.local (p5099778e.dip0.t-ipconnect.de. [80.153.119.142]) by mx.google.com with ESMTPSA id bd8sm38114774wjc.21.2015.02.19.08.36.29 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Feb 2015 08:36:30 -0800 (PST) Message-ID: <54E6110C.7080600@gmail.com> Date: Thu, 19 Feb 2015 17:36:28 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Anthony Ferrara CC: francois@php.net, Lester Caine , "internals@lists.php.net" References: <54E5F401.2050108@gmail.com> In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Using Other Channels (was Scalar Type Declarations v0.5) From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > Based on the no reasons that people presented, and some back-of-envelope math. That is not "knowing", much less "**knowing**". That is a guess based on an estimate and set of assumptions, some of which very well may be wrong (such as, people can have more than one reason to vote no). > The reason is, with strict typing you only need to deal with 8 > possible states for every variable (int, float, bool, resource, array, > object, callable, null and string). And many of those states you can > eliminate based on context (you know an argument passed to an int > declared parameter will always be an int). This is possible with coercive typing too, if the argument is declared int then it will be coerced to int. > Without strict typing, you also need to consider virtual states: > castable object (internally implementing get()), stringable object > (implementing __tostring), numeric string ("123"), kind-of numeric > string ("123 abc"), etc. And many of those states *can't* be > eliminated based on context. I don't see why you don't need to consider them anyway - if your analyzer cares about ability of the object to be casted to a string, you'd have to carry this information anyway - for use in (string), echo, "$foo", internal functions, etc. So again no advantage here. > An example is that ($a + $b) we know can never produce a string. We > know it can never produce a bool, resource, array, callable or null. > The only things it can produce is an object, an int or a float. So if > we see expressions of the form `$c = ($a + $b)`, we can immediately > deduce something about $c and therefore reduce the number of possible > states. This is right, but no advantage to strict typing here, this is true under any typing model. > With strict typing, if we then pass $c to a function expecting int, we > know that C must be an int. Which means that $a and $b therefore That seems to be an incorrect assumption - passing something to function asking for an int doesn't mean it is an int. It means that inside function it would be int or fail happens, but that is achieved with coercive typing too, so no advantage to strict typing here. Of course, since we already know $c is an int or a float or an object, no additional information here is obtained, and we do not know anything about $c itself - we only know the "A->B" is true but we don't know whether A is true and thus not whether B is true. > **must** be castable to an integer (otherwise an error will be thrown > down the road). So we've just reduced $a down to 5 types: int, numeric > string, null, bool and castable object (from at least 12). And $b the Yes, after the expression is done and *if* it did not error out, we can deduce some things about $a's value *after* the expression. But we have no guarantees the expression would succeed and no advantage to string typing which does not come into play here at all. > same. So our expression has 10 possible valid (non-error-case) > permutations. Down from the approximately 432 possibilities before > hand (12 for $a, 12 for $b, 3 for $c). And that's with unknown $a and > unknown $b. Still don't see any advantage to strict typing here. Deduction about the behavior of + can be made without any strict typing involved, as far as I can see. > With strictly typed $a and $b, the expression drops to 1 possible > permutation. And you can detect if it's a valid one. And many static > analysis engines do this. I didn't see any proposal that proposes strictly types variables. As for parameters, both strict and coercive typing provide knowledge about the types of parameter inside the function they are defined in, so no advantage to strict typing here. > It's not that static analysis is impossible without strict typing. > It's that it gets drastically easier. Both in terms of processing It may be so, but yet again it was not demonstrated. > Does that substantiate the claim? If not, I'm definitely open to > discussing it further. So far I did not see any substantiation, unless I have not understood what your analyzer is doing. -- Stas Malyshev smalyshev@gmail.com