Bug #68445 [NEW]: Optional arguments may precede required arguments in function declarations

From: Date: Tue, 18 Nov 2014 19:47:12 +0000
Subject: Bug #68445 [NEW]: Optional arguments may precede required arguments in function declarations
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188661@lists.php.net to get a copy of this message
From:             ajf at ajf dot me
Operating system: OS X Yosemite
PHP version:      5.6.3
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:Optional arguments may precede required arguments in function declarations

Description:
------------
Optional arguments can be specified before required arguments, which
would suggest that you can omit them. Yet, if you actually call the
function, it will complain that you didn't pass the required arguments.

The fix would be either to support optional arguments before required
arguments at call-time, or to error when this is done in a function
declaration.

Test script:
---------------
<?php

function foo($a = NULL, $b) {
    var_dump($b);
}

foo(2);


Expected result:
----------------
int(2)

Actual result:
--------------
Warning: Missing argument 2 for foo(), called in %s on line 7 and
defined in /in/b1HC3 on line 3

Notice: Undefined variable: b in %s on line 4
NULL 

-- 
Edit bug report at https://bugs.php.net/bug.php?id=68445&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=68445&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=68445&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=68445&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=68445&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=68445&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=68445&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=68445&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=68445&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=68445&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=68445&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=68445&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=68445&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=68445&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68445&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=68445&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=68445&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=68445&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68445&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=68445&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=68445&r=mysqlcfg



Thread (8 messages)

« previous php.bugs (#188661) next »