Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:44573 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84868 invoked from network); 1 Jul 2009 17:00:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Jul 2009 17:00:23 -0000 Authentication-Results: pb1.pair.com header.from=ilia@prohost.org; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=ilia@prohost.org; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain prohost.org from 209.85.220.224 cause and error) X-PHP-List-Original-Sender: ilia@prohost.org X-Host-Fingerprint: 209.85.220.224 mail-fx0-f224.google.com Received: from [209.85.220.224] ([209.85.220.224:65289] helo=mail-fx0-f224.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 95/C0-15456-F169B4A4 for ; Wed, 01 Jul 2009 13:00:20 -0400 Received: by fxm24 with SMTP id 24so1061211fxm.23 for ; Wed, 01 Jul 2009 10:00:06 -0700 (PDT) Received: by 10.204.100.201 with SMTP id z9mr9716662bkn.168.1246467603694; Wed, 01 Jul 2009 10:00:03 -0700 (PDT) Received: from ?192.168.1.132? (CPE0018f8c0ee69-CM000f9f7d6664.cpe.net.cable.rogers.com [99.238.11.214]) by mx.google.com with ESMTPS id h2sm2293936fkh.16.2009.07.01.10.00.01 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 01 Jul 2009 10:00:02 -0700 (PDT) Message-ID: To: PHP internals Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v935.3) Date: Wed, 1 Jul 2009 12:59:59 -0400 X-Mailer: Apple Mail (2.935.3) Subject: RFC: Type hinting revisited for PHP 5.3 From: ilia@prohost.org (Ilia Alshanetsky) There has been quite a bit of discussion on this list, IRC, developer meetings, etc... about introduction of type hinting to PHP. Most people appear to think that this would be a good idea, but there is a reason why it is not in PHP already. The main source of conflict appears to be that in some cases typical type hinting is just too strict for PHP's typeless nature (most people expect that "1" == 1, while int type hint would definitely reject string "1"). Personally, I disagree with that opinion, but I can understand people who raise that issue. At work we've been using PHP 5.2 with type hinting for nearly 2 years now with great success, it makes code much easier to read and understand and the security benefit of type hinting is not to be under valued. In many cases type hinting can present a last line of defense against unexpected input for numeric fields, which are typically abused to do SQL injection. I've taken a few hours this morning to port my 5.2 type hinting patch to 5.3. In recognition of a need for a more 'flexible' numeric type I've introduced (numeric) type hint that would allow bool/int/float data types as well as a string containing a numeric entity as identified by is_numeric_string(). For completion i've also added (scalar) data type that will allow any scalar data element. The patch is available here: http://ia.gd/patch/type_hint_53.txt It should be noted that this patch is fully compatible with opcode caches and and requires no changes on the part of an opcode cache such as APC to work. My hope is that the latest changes will allow this to become a standard part of PHP. Ilia Alshanetsky P.S. It should be noted that this is not the first idea for type hints, that credit goes to Hannes Magnusson who had posted a similar patch on the internals list back in 2006. Also, back in 2008 Felipe Pena wrote a type hinting patch for PHP that is available on wiki.php.net.