Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86206 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14339 invoked from network); 14 May 2015 05:20:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 May 2015 05:20:01 -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.174 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.214.174 mail-ob0-f174.google.com Received: from [209.85.214.174] ([209.85.214.174:32829] helo=mail-ob0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 12/C1-31470-08034555 for ; Thu, 14 May 2015 01:20:00 -0400 Received: by obblk2 with SMTP id lk2so45946744obb.0 for ; Wed, 13 May 2015 22:19:58 -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=nEXYTcOeeiVlALNWyKqFe8tn40gJswfKz2K2yC1qHnk=; b=VBDaV1qsWJuaqWno/avJxLjqNNap4blTLoHonzpxNasTk25ZyjqsRa0uTTwmiVaiRN l0NfOQPQx67FpSWuLhBaDfhtpxsBpOdEcubQjr5jUvlCEnPNd55rYjBexAWj6nqwyfVg COCLTAKkkIkJOW/B1Gn8WWGxByBKjdnJ3FKdZqgaRHKKlEYz5NdtgsKAtH6059yfSDky zZpoeHhbi6Fx5ilHSrpWvKPvkC4KSKvszFdFw8/WgucGdIZUS0d7vhL53It4SynbaQZ9 32FShp31pfEbnBmyRsElwRS0DrsG8wRn1Ig1ieZJzAD8lSuXSDCx3sik5fmf6T6757hc S0Dg== X-Received: by 10.202.10.193 with SMTP id 184mr1927550oik.90.1431580798258; Wed, 13 May 2015 22:19:58 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.202.104.196 with HTTP; Wed, 13 May 2015 22:19:17 -0700 (PDT) In-Reply-To: <55518D59.6070108@gmail.com> References: <55518D59.6070108@gmail.com> Date: Thu, 14 May 2015 14:19:17 +0900 X-Google-Sender-Auth: vSRpGamva2X_bmxcWHThXGLFovc Message-ID: To: Stanislav Malyshev Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a113d1dc6f294ee051603e04a Subject: Re: [PHP-DEV] is_digits() and digits type From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a113d1dc6f294ee051603e04a Content-Type: text/plain; charset=UTF-8 Hi Stas, On Tue, May 12, 2015 at 2:19 PM, Stanislav Malyshev wrote: > > - is_digits() and digits type for digits only inputs(integer like > string) > > - is_numeric() and numeric type for float like string > > This is not what types are in PHP, and not what they should be, IMO. If > you want to assign arbitrary checks to a variable, I would suggest using > a class with a suitable constructor. If you think it's too slow (meaning > you are doing very heavy in-memory data processing and nothing else), > make an extension - it would be roughly the same speed as native PHP > types. If you want it to be extensible - then you may be looking for > something like pre/post conditions and DbC, but this is another story > for which we need proper RFCs, etc. > I agree that validation and DbC is far better than resolution I proposed here. I guess DbC will not prevent users from abusing type hints, though. > However, calling random combination of native types, objects and string > constraints "type" because somewhere there's use case for it does not > look like a good design for a language. It's too random and ad-hoc. If we aren't going to change any, we need large warning in the manual, explain nature of external data, compatibility issues between 32 bit and 64 bit CPU, what kind of data is appropriate for native type hints, etc. It's not a difficult job to do. How about have functions check if value fits to certain data types, 32 bit int, 64 bit int and IEEE double? We may add/extend is_digits()/is_numeric() for this. It would be handy for DbC also. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a113d1dc6f294ee051603e04a--