Bug #70941 [NEW]: Optional parameter identified as required

From: Date: Thu, 19 Nov 2015 13:36:29 +0000
Subject: Bug #70941 [NEW]: Optional parameter identified as required
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197333@lists.php.net to get a copy of this message
From: devosc at gmail dot com Operating system: PHP version: 7.0.0RC7 Package: Reflection related Bug Type: Bug Bug description:Optional parameter identified as required Description: ------------ The order in which an optional parameter is specified should not matter. However, currently, when an optional parameter occurs before a required parameter in a constructor or function argument, the Reflection package is incorrectly identifying the optional parameter as being a required parameter. Test script: --------------- <?php class A {} class B { function __construct($b = null, A $a) {} } Reflection::export(new ReflectionClass('B')); class C { function __construct(A $a, $b = null) {} } Reflection::export(new ReflectionClass('C')); https://3v4l.org/gKhZ6 https://3v4l.org/Yt2JN Expected result: ---------------- Parameter b should be optional regardless of its position in a constructor or function argument. Actual result: -------------- Class [ <user> class B ] { @@ ./index.php 10-12 - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [0] { } - Methods [1] { Method [ <user, ctor> public method __construct ] { @@ ./index.php 11 - 11 - Parameters [2] { Parameter #0 [ <required> $b ] Parameter #1 [ <required> A $a ] } } } } Class [ <user> class C ] { @@ ./index.php 16-18 - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [0] { } - Methods [1] { Method [ <user, ctor> public method __construct ] { @@ ./index.php 17 - 17 - Parameters [2] { Parameter #0 [ <required> A $a ] Parameter #1 [ <optional> $b = NULL ] } } } } -- Edit bug report at https://bugs.php.net/bug.php?id=70941&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70941&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70941&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70941&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=70941&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=70941&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=70941&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=70941&r=needscript Try newer version: https://bugs.php.net/fix.php?id=70941&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=70941&r=support Expected behavior: https://bugs.php.net/fix.php?id=70941&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=70941&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=70941&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=70941&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70941&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=70941&r=dst IIS Stability: https://bugs.php.net/fix.php?id=70941&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=70941&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=70941&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=70941&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=70941&r=mysqlcfg

« previous php.bugs (#197333) next »