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 <yohg...@ohgaki.net> wrote: > Hi Christoph, > > On Thu, Apr 30, 2015 at 6:27 AM, Christoph Becker <cmbecke...@gmx.de> > wrote: > > > > On Wed, Apr 29, 2015 at 9:33 AM, Ryan Pallas <derokor...@gmail.com> > > 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 > > >> <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 > yohg...@ohgaki.net >