Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86034 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 24168 invoked from network); 29 Apr 2015 21:41:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Apr 2015 21:41:14 -0000 Authentication-Results: pb1.pair.com header.from=thegreatall@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=thegreatall@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.175 as permitted sender) X-PHP-List-Original-Sender: thegreatall@gmail.com X-Host-Fingerprint: 209.85.214.175 mail-ob0-f175.google.com Received: from [209.85.214.175] ([209.85.214.175:35851] helo=mail-ob0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BD/74-26317-9FF41455 for ; Wed, 29 Apr 2015 17:41:13 -0400 Received: by obbeb7 with SMTP id eb7so30576758obb.3 for ; Wed, 29 Apr 2015 14:41:10 -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:date:message-id:subject :from:to:cc:content-type; bh=OeBIt0PlTLsCX5CponT2l7iGcGU0jMrEnrmBStoUm6g=; b=wSCzliHqYLIgX9f3pSuQU5yx9XkvyF+X85/R8Jk5S8lKGCWMueMYVOH0U2LmWhSKDp 4/YPGRJQ8rAxcoNhc7lJlrwZbk/m7712CVe5oFrpxelLBVzdyxkGtqtWPiZwJvwEWMHS 1QvxFgcGz/ajDrcQQdT+StMZcj7VtQbofJHQ0cQ0udJNvrK2q5xpsAMfDr167LTa9ma7 CMEP/imVYoPmqH0ilo8PF+f0c02W8mvE7d3w98jj9ZEnUO9+vi8UjRaO8SjxHhl+PQbW xmXjt+q1nb3pJGYQO0xQYqHHpD1yGfjnY8f2qhEnrC46iaKUgLVRhIDw3Rjts5+5JHjw j+lg== MIME-Version: 1.0 X-Received: by 10.202.13.132 with SMTP id 126mr225571oin.2.1430343669941; Wed, 29 Apr 2015 14:41:09 -0700 (PDT) Sender: thegreatall@gmail.com Received: by 10.76.71.193 with HTTP; Wed, 29 Apr 2015 14:41:09 -0700 (PDT) In-Reply-To: References: <55401F31.9030703@gmail.com> <55414CC5.7000503@gmx.de> Date: Wed, 29 Apr 2015 14:41:09 -0700 X-Google-Sender-Auth: -gPUrsCy1EWZHpTtMCpzK0RnKZo Message-ID: To: Yasuo Ohgaki Cc: Christoph Becker , Ryan Pallas , Stanislav Malyshev , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a113d162c5a8aff0514e3d6a4 Subject: Re: [PHP-DEV] Adding "numeric" type hint From: nathanbruer@gmail.com (Nathan Bruer) --001a113d162c5a8aff0514e3d6a4 Content-Type: text/plain; charset=UTF-8 This has been a big issue that I have ran into many times in the past for large framework projects, instead of building it out with "strict" types like: int, float, string, exc... It makes more sense to allow a user to define a psudo-type themselves which PHP will pass the arguments into to be "cleaned" by the user then let the function deal with the arguments. For example: function force_int($value){ return (int) $value; } function must_be_string($v){ if(!is_string($v)){ throw new Exception("Not String"); } return (string) $v; } function foo(*force_int $val, *must_be_string $str){ // $val will always be an int if it ever gets here // $str will always be a string if it gets here echo $val, " ", $str; } foo("foo", "bar"); // returns '0 bar' foo("1", "2"); // returns '1 2' foo(1, 2); // fatal error because second argument threw exception foo(1, "2") // returns '1 2' foo("hi", 2) // fatal error because second argument threw exception foo("hi", "2") // returns '0 2'; On Wed, Apr 29, 2015 at 2:39 PM, Yasuo Ohgaki wrote: > Hi Christoph, > > On Thu, Apr 30, 2015 at 6:27 AM, Christoph Becker > wrote: > > > > On Wed, Apr 29, 2015 at 9:33 AM, Ryan Pallas > > wrote: > > > > > >> 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 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. > > > > A solution for this issue has been proposed by the "Big Integer Support" > > RFC which has been withdrawn. It's too late for PHP 7.0 to re-open it, > > but it might be reasonable to to so for PHP 7.1. > > > I don't think breaking a lot of code under 32 bit machines with PHP 7.0 > is not good thing to do. > > In addition, current code does not even allow GMP object as "int". > http://3v4l.org/GiklL > > Regards, > > -- > Yasuo Ohgaki > yohgaki@ohgaki.net > --001a113d162c5a8aff0514e3d6a4--