Thursday, September 5, 2013

PHP - Why is it not possible to use ~PHP_INT_MAX as a default argument

PHP - Why is it not possible to use ~PHP_INT_MAX as a default argument

I'm wrote a function in which I was using PHP_INT_MAX and ~PHP_INT_MAX as
the default arguments but I ended up getting a syntax error for '~'. The
declaration is:
public static function isNumberValid($number, $lowerbound = ~PHP_INT_MAX,
$upperbound = PHP_INT_MAX)
I fixed it by making $lowerbownd = null in the declaration and then
setting it in the body and now it works perfectly fine:
if (is_null($lowerbound)){
$lowerbound = ~PHP_INT_MAX;
}
I was just wondering why that is..

No comments:

Post a Comment