Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34471 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 47920 invoked by uid 1010); 4 Jan 2008 19:23:52 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 47900 invoked from network); 4 Jan 2008 19:23:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Jan 2008 19:23:52 -0000 Authentication-Results: pb1.pair.com smtp.mail=sam@sambarrow.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=sam@sambarrow.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain sambarrow.com from 205.234.132.11 cause and error) X-PHP-List-Original-Sender: sam@sambarrow.com X-Host-Fingerprint: 205.234.132.11 scottsdale.servershost.net Received: from [205.234.132.11] ([205.234.132.11:38171] helo=scottsdale.servershost.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 99/53-63281-7C78E774 for ; Fri, 04 Jan 2008 14:23:51 -0500 Received: from [98.172.154.66] (port=61779 helo=[10.200.100.14]) by scottsdale.servershost.net with esmtpsa (SSLv3:RC4-MD5:128) (Exim 4.68) (envelope-from ) id 1JAs8u-0008JS-Hm; Fri, 04 Jan 2008 13:23:44 -0600 To: Stefan Esser Cc: Stanislav Malyshev , internals Mailing List In-Reply-To: <477E853E.5000308@sektioneins.de> References: <477DB7BF.10201@chiaraquartet.net> <20080104105558.GC7861@mint.phcomp.co.uk> <477E5649.2080104@chiaraquartet.net> <477E619C.2050107@sektioneins.de> <477E79AE.6050407@zend.com> <477E853E.5000308@sektioneins.de> Content-Type: text/plain Date: Fri, 04 Jan 2008 14:22:07 -0500 Message-ID: <1199474527.15292.208.camel@sbarrow-desktop> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-Antivirus-Scanner: Clean mail though you should still use an Antivirus X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - scottsdale.servershost.net X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - sambarrow.com X-Source: X-Source-Args: X-Source-Dir: Subject: Re: [PHP-DEV] type hinting From: sam@sambarrow.com (Sam Barrow) On Fri, 2008-01-04 at 20:13 +0100, Stefan Esser wrote: > Stanislav Malyshev schrieb: > >> * the code gets smaller because not so many typechecks in every function > > What do you mean "not so many"? You need one per checked parameter. > There is a difference in complexity between a userlevel type check and a > low level type check. Definitely. User-level is 10 times more written code and is slower. > >> * with type hints byte code optimizer can optimize the code far better > > Do you have any optimizer that can do that? Any plans to make one? Any > > tests showing you can optimize real-life application this way? > How should one have an optimizer for that as long PHP does not have this > feature? Noone would implement one that is capable of doing this not > knowing if the feature ever makes it into PHP. Very true, thank you for pointing that out. > > That is true, type hints do make static analysis easier - strict > > typing is created exactly for that purpose. However, it only helps if > > all the code is strictly typed - otherwise you just move point of > > failure around. And in any case, type won't help you much form most > > real static analysis purposes, such as security - "string" can hold > > anything. > That is not completely true. If for example 10 functions use type > hinting and other functions not, then you have atleast 10 functions > where you can analyse better. > > A "simple" example is: > > function decryptID($id) > { > return $id ^ SOME_RUNTIME_CONSTANT; > } > > function getUserFromId($id) > { > $sql = "select * from user where id=".decrypt($id); > ... > } > > To analyse this construct a static code analyser has a lot todo and it > still needs to check every call to getUserFromId() to verify if this is > an actual security hole, because it doesn't know the content of > SOME_RUNTIME_CONSTANT and therefore the return value of decryptID could > be a binary xored string. However a type hint of int in the decryptID() > function would allow the analyser to know that decryptID() always return > int and this would tell it that this is not a security hole. You see in > this example that just partial usage of type hinting can mean the > difference between a false positive and a definitive unexploitability. In general, type hinting gives you more control over your code. Also, if $id is an int, you prevent having to escape the data to avoid sql injection. > Greetings, > Stefan Esser >