Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86029 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16065 invoked from network); 29 Apr 2015 21:16:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Apr 2015 21:16:05 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.171 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.214.171 mail-ob0-f171.google.com Received: from [209.85.214.171] ([209.85.214.171:36757] helo=mail-ob0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 29/B2-26317-21A41455 for ; Wed, 29 Apr 2015 17:16:02 -0400 Received: by obbeb7 with SMTP id eb7so30134424obb.3 for ; Wed, 29 Apr 2015 14:15:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=ga6Mud7roWtj3ZebThHcmbWSYVwPxb0GUrF4TYME1+Y=; b=II1GbBhQvxMnMyp7z8cH6EgIq3Sf+JQ7F4dEja5p8abYNHHfyjCu6NTOne9YZcGJG7 WKXMXn9gVoXMogb7iPNGsRQwmhIBjWJ3EphWtc2bbS0+jtp861Q62zGFJpvZp5wg9vo7 pmIxtJv6erUprYT53/6awsHMvoWkZ/pfM3fcp7sg8582UMJHKJuJ+dplRogBvobWz1jp /4BHy25hw66WH2XCQt8w51+y2vd/QXNv4oSfs/XswZPX+JyfP8DALB/A9f/eTyyUiPq6 d33SH01w7w0+9HzlbelB1s62oI48//RTLB5KQmz5UFby9Mz+tnZitYiYkmfpIMyqvFy4 AVdQ== X-Received: by 10.202.90.197 with SMTP id o188mr842453oib.62.1430342159107; Wed, 29 Apr 2015 14:15:59 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.202.104.196 with HTTP; Wed, 29 Apr 2015 14:15:18 -0700 (PDT) In-Reply-To: References: <55401F31.9030703@gmail.com> Date: Thu, 30 Apr 2015 06:15:18 +0900 X-Google-Sender-Auth: YvSO-JuGtubmCAWcwDP2bW0BtHU Message-ID: To: Ryan Pallas Cc: Stanislav Malyshev , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a113d36be4d0d290514e37c7c Subject: Re: [PHP-DEV] Adding "numeric" type hint From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a113d36be4d0d290514e37c7c Content-Type: text/plain; charset=UTF-8 Hi Stas and Ryan, On Wed, Apr 29, 2015 at 9:33 AM, Ryan Pallas wrote: > > 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. > The objective to have type "hint" is to remove such checks by users, isn't it? Do you really think all users will write such code for database/json/etc values? The issue is that weak mode type hint is *not* weak at all. It forces to have machine native type rather than it's data form. PHP apps are easily broken by too large value because PHP stops execution by fatal error. i.e. DoS became easy. I will never write such code, but I don't want to check and fix library that I would like to use. I don't think I can manage programmers to do that even if they are under my control. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a113d36be4d0d290514e37c7c--