Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86007 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 4907 invoked from network); 29 Apr 2015 00:34:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Apr 2015 00:34:45 -0000 Authentication-Results: pb1.pair.com smtp.mail=derokorian@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=derokorian@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.54 as permitted sender) X-PHP-List-Original-Sender: derokorian@gmail.com X-Host-Fingerprint: 74.125.82.54 mail-wg0-f54.google.com Received: from [74.125.82.54] ([74.125.82.54:34866] helo=mail-wg0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9D/71-30735-42720455 for ; Tue, 28 Apr 2015 20:34:44 -0400 Received: by wgyo15 with SMTP id o15so11634060wgy.2 for ; Tue, 28 Apr 2015 17:33:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=SDLJoTgiwG+sdyBgDe3Ja/cLuYRM+1l7uTG5Z9+qveM=; b=qmFitEXJXjHqWE+OoY6/PO3kYoGnimabVFH7xvoB9vfl8AWurfFTsHWuVcJbbg3hBW Im90gPD4LcL0KLYkzrbItKq1SPKMwwiTjVH928rzrr/BilKBtPQBBUovmFE/C/OE7vni 3rUJbuGTXafCDYCE65u7xcDVU54y9mRnRA1PzZHsCGAL704Xh8z+LzYfAEivGMc/Lwe1 kzYasLulxxXzmGz2sN2gSlnhWyGCRWr2egBGIHX6bD3UEvxYN1PPnMIfG3vpF2iUmybL xYegY+EXrNMdj+tmLfO+ZLSXWoPaCN2kSPwAu52baD/cnizm7xNuozXvezgnvV/p9VIk hOAA== MIME-Version: 1.0 X-Received: by 10.180.107.38 with SMTP id gz6mr849750wib.63.1430267618663; Tue, 28 Apr 2015 17:33:38 -0700 (PDT) Received: by 10.28.7.196 with HTTP; Tue, 28 Apr 2015 17:33:38 -0700 (PDT) In-Reply-To: <55401F31.9030703@gmail.com> References: <55401F31.9030703@gmail.com> Date: Tue, 28 Apr 2015 18:33:38 -0600 Message-ID: To: Stanislav Malyshev Cc: Yasuo Ohgaki , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=e89a8f2356ad58200c0514d22156 Subject: Re: [PHP-DEV] Adding "numeric" type hint From: derokorian@gmail.com (Ryan Pallas) --e89a8f2356ad58200c0514d22156 Content-Type: text/plain; charset=UTF-8 On Tue, Apr 28, 2015 at 6:00 PM, Stanislav Malyshev wrote: > 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. > I agree with Stanislav here, if you want to accept any type of number, its easy enough to add your own checking to do that with the wonderful is_numeric. And for simplicity, make an invalidArgument method that you can call after manually checking if arguments are wrong: *http://3v4l.org/r0qO0 * Works for all versions this tool runs as well. -Ryan > > -- > Stas Malyshev > smalyshev@gmail.com > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --e89a8f2356ad58200c0514d22156--