|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76385 Value of PHP_INT_MIN cannot be used as default value for int parameter
Submitted: 2018-05-29 06:16 UTC Modified: 2018-05-29 11:25 UTC
Avg. Score:3.0 ± 0.8
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:2 (66.7%)
From: Assigned: cmb (profile)
Status: Duplicate Package: Scripting Engine problem
PHP Version: 7.2.6 OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


 [2018-05-29 06:16 UTC]
$ cat a.php 

$ cat b.php 
function f(int $i = -9223372036854775808)

$ php -nv
PHP 7.2.6 (cli) (built: May 22 2018 16:22:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

$ php -n a.php 

$ php -n b.php 
Fatal error: Default value for parameters with a integer type can only be integer or NULL in /home/sb/b.php on line 2


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-29 06:26 UTC]
It appears that the value of PHP_INT_MIN is generally not recognized as being an integer value:

$ cat a.php 


$ php -n a.php
 [2018-05-29 06:44 UTC]
The value of PHP_INT_MIN (but not of PHP_INT_MAX) is a float apparently. 

You can use

    function f(int $i = PHP_INT_MIN) {}

as a workaround.
 [2018-05-29 06:57 UTC]
It appears I stripped down the problem I am faced with too much for this bug report. I am sorry about that.

I came across this in the context of More specifically,

When function f(int $i = PHP_INT_MIN) {} is introspected using the Reflection API, getDefaultValue() does not return "PHP_INT_MIN" for $i but rather the value of that constant.

And while I think that the Reflection API should be extended to optionally return the "real" default value as it stands in the code, I still believe that function f(int $i = -9223372036854775808) {} should work.
 [2018-05-29 07:21 UTC]
-Status: Open +Status: Verified
 [2018-05-29 07:21 UTC]
This bug is hilarious:
The problem is that PHP parses "-9223372036854775808" not as a negative number but as a "-" followed by "9223372036854775808". The latter value is, of course, just barely too large for an integer so it overflows to a float.
 [2018-05-29 11:25 UTC]
-Status: Verified +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2018-05-29 11:25 UTC]
Actually, this is a duplicate of bug #53934.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Oct 28 14:01:23 2020 UTC