Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86005 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 114 invoked from network); 28 Apr 2015 23:51:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Apr 2015 23:51:34 -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.178 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.214.178 mail-ob0-f178.google.com Received: from [209.85.214.178] ([209.85.214.178:34652] helo=mail-ob0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2C/90-30735-50D10455 for ; Tue, 28 Apr 2015 19:51:34 -0400 Received: by obfe9 with SMTP id e9so8701573obf.1 for ; Tue, 28 Apr 2015 16:51:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:from:date:message-id:subject:to:content-type; bh=e9Tgaa5HTO4Lv9NV7RSCKhTVLeRaZECQkyppJ1W9tMo=; b=vyD7O23N8MxTWrYUY49lhlQNy0KOJCAq3XqLqV/OXx7a94nG5Om6zCHZ0E4ytoPdgF /q+kjuEnVPV2WJKOJXIDGc9zMD66BFvceKzHU+MYjtSZ4Wp+logonUxCXriKpcBFlBud B7+HjoWBo902fDxVKTmDP3fBssGLBCKxafLxvzoZjJ2UpYaqxv+RW0zNghnnRILEeHVZ Ii+0YFwmMRhMCpuL/FgVGnwoUJ7O05wj3ZqeK0UsS4bNEL1TZqFQz935ZlPvrrPOAd+j Rg46YDdSqzc/OSeczO9tkhZwI7imy4sx/yWyP/Ipgh7Ghpp6ua9S4m6oDcVM7mbV5EF8 SlBw== X-Received: by 10.202.90.197 with SMTP id o188mr15690577oib.62.1430265090768; Tue, 28 Apr 2015 16:51:30 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.202.104.196 with HTTP; Tue, 28 Apr 2015 16:50:50 -0700 (PDT) Date: Wed, 29 Apr 2015 08:50:50 +0900 X-Google-Sender-Auth: nNbQIHX7RPQWmxnAVUJl7i2u1iE Message-ID: To: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a113d36beab86eb0514d18af2 Subject: Adding "numeric" type hint From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a113d36beab86eb0514d18af2 Content-Type: text/plain; charset=UTF-8 Hi all, 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. http://3v4l.org/6J0bZ There are cases that programmer want/need to handle any numeric values. e.g. JSON numeric, Database numeric, PHP's array key beyonds INT min/max, Values for BCMath/GMP, etc. It's common for 32 bit platforms. For example, we cannot do query database safely with "int" type hint. e.g. function get_some_db_record(int $id) {} Most databases uses 64 bit signed int for database IDs, but this code limits $id to 32 bit signed int for 32 bit platforms. There are databases that allow unsigned 64 bit int ID. 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 use "string" type hint even if apps need large numbers. How about have "numeric" type hint that accepts any format/class(GMP) of numeric values? function foo(numeric $var) { // do something useful with numeric value } To be honest, I would like to have StrictSTH RFC behavior for weak mode int/float type hints to make sure "int"/"float" has integer/float form/value always, 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 app suddenly emits fatal error and exits when database/json returns value beyond int/float. http://3v4l.org/6J0bZ (See how it works with large string integer value) Any comments? Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a113d36beab86eb0514d18af2--