[PHP-BUG] Req #76412 [NEW]: Nullable type default value
[email protected] ("ionuthrive at yahoo dot com") Tue, 5 Jun 2018 08:55:58 GMT
| Newsgroups | php.standards |
|---|---|
| Message-ID | <[email protected]> |
From: ionuthrive at yahoo dot com
Operating system: All
PHP version: 7.2.6
Package: PHP Language Specification
Bug Type: Feature/Change Request
Bug description:Nullable type default value
Description:
------------
When passing null to a optional nullable type argument, the default
value is overwritten.
Test script:
---------------
<?php
function get(string $id, ?int $limit = 1, ?string $type = 'standard',
?array $options = []){
var_dump($limit);
var_dump($type);
}
get(1, null, 'custom');
get(1, 10, null, ['my'=>'option']);
Expected result:
----------------
Since 7.1 when the nullable types could be marked as null the situation
where one needs to call a function while skipping some parameters is met
with overwrite of the default values of the function arguments.
For the above test script, when passing null and the argument is
specifically declared as a nullable type, the parser should know to take
the default value instead of overriding it as NULL.
feature-php.php:4:
1
feature-php.php:5:
string(6) "custom"
feature-php.php:4:
int(10)
feature-php.php:5:
standard
Actual result:
--------------
feature-php.php:4:
NULL
feature-php.php:5:
string(6) "custom"
feature-php.php:4:
int(10)
feature-php.php:5:
NULL
--
Edit bug report at https://bugs.php.net/bug.php?id=76412&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76412&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76412&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76412&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76412&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76412&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76412&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76412&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76412&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76412&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76412&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76412&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76412&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76412&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76412&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76412&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76412&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76412&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76412&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76412&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76412&r=mysqlcfg