Re: Return Type Hinting for Methods RFC

From: Date: Thu, 22 Dec 2011 18:55:21 +0000
Subject: Re: Return Type Hinting for Methods RFC
References: 1 2 3 4 5 6 7 8 9 10 11 12  Groups: php.internals 
Request: Send a blank email to internals+get-57012@lists.php.net to get a copy of this message
Hi!
      function age_check($age)
      {
          if (!is_int($age)) {
              throw new InvalidArgumentException;
          }
      }
With the above code, the caller needs to cast and the writer of the age_check() function has to copy/paste/adapt these checks to all the correct places ...
That's because you should be using is_numeric in this context ;) And have an answer on the question "what happens if it's not" that does not involve "throwing exception that nobody is going to catch". Of course, you can't design proper library in one line. The idea is that strict typing doesn't make such design easier, since it does not lead to less work. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227

« previous php.internals (#57012) next »