Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86006 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2031 invoked from network); 29 Apr 2015 00:01:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Apr 2015 00:01:15 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.47 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.220.47 mail-pa0-f47.google.com Received: from [209.85.220.47] ([209.85.220.47:36641] helo=mail-pa0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2A/F0-30735-94F10455 for ; Tue, 28 Apr 2015 20:01:14 -0400 Received: by pabsx10 with SMTP id sx10so10467735pab.3 for ; Tue, 28 Apr 2015 17:01:10 -0700 (PDT) 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:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=P9zsfLEcZuLvU7PvafZmfZe59ljEoAeDoM1jv8ANFLQ=; b=WAqfnit6lv/CKM7Gq/zuOJkKI67XG0M9nu3LSxX/DNs3sUAY8bwkjP+cvtzrggytZg DMexUll4R5RjYBmB4fYnhKg2LvX1k6b/xGlUaNlXkuOPakcwhPo5ZuugZ5Q/tetZo8/o PA4M+VN6zQKqIdD+zF5FyeRppRRUKw2HLQV9hGkmzVx39ArbA3bNPtwnmLZ4A0sc29MG VhvxRnddhfMIbKsuIUGc1he+4JaAiGdtdKeoaseUwBa8/0ZvImHQBNEAeNAnY7M0okjg BV2as+NveYvnzvwBjxPoMV2/dyUvYhYAyvdpKNUxXFhKq5D1tkWheWGfrVezlMMkGFfA KCUw== X-Received: by 10.66.140.101 with SMTP id rf5mr37248798pab.50.1430265670762; Tue, 28 Apr 2015 17:01:10 -0700 (PDT) Received: from Stas-Air.local (108-66-6-48.lightspeed.sntcca.sbcglobal.net. [108.66.6.48]) by mx.google.com with ESMTPSA id m4sm23513409pdo.78.2015.04.28.17.01.09 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Apr 2015 17:01:09 -0700 (PDT) Message-ID: <55401F31.9030703@gmail.com> Date: Tue, 28 Apr 2015 17:00:49 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Yasuo Ohgaki , "internals@lists.php.net" References: In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Adding "numeric" type hint From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > External data can have any form of numbers. > Current PHP can handle them as "string". However PHP7's type hint cannot > handle numeric data well because it only has "int" and "float" hints. This is exactly what's wrong with strict typing in PHP. However, if you use real numeric string and do not enable strict typing - it works just fine. We don't need more types for this. > There are cases that programmer want/need to handle any numeric values. There also cases when programmer needs to handle Roman numbers, phone numbers, valid XML strings and TCP/IP headers. But we should not add types into the language for those. > To avoid this problem, users must use "string" type hint and have to > validate > parameter by themselves. This ruins benefits of type hint. Most PHP will not Typing is not solution for every data restriction, especially not in PHP. If you app needs strings that can not be represented by PHP basic types, you need custom validation code. > but "numeric" type hint may do the job. One function with "int"/"float" > type hint > could break app with current type hint implementation, though. i.e. Working If you type your parameter, then you declare "I want this to fail if the parameter is not of this type". Then you can't complain when it fails - that's exactly what you asked for. -- Stas Malyshev smalyshev@gmail.com