[PHP-BUG] Req #69028 [NEW]: Allow variable default function parameters
[email protected] ("martin at glooware dot com")
| Newsgroups | php.standards |
|---|---|
| Message-ID | <[email protected]> |
From: martin at glooware dot com
Operating system: all
PHP version: Irrelevant
Package: PHP Language Specification
Bug Type: Feature/Change Request
Bug description:Allow variable default function parameters
Description:
------------
Currently it's not possible to use any constants, variables or anonymous
functions in a function parameter as default value. This is for example
not possible:
function saveUser($name, $surname, $company = CONSTANT_COMPANY_VALUE)
{}
... or even this ...
function calculateGravitationalPull($rotation, $axis, $speed,
$grav_const = (3.234 / $rotation * $speed)) {}
I've come across various situations, like the example ones above, where
I'd love to be able to inject a configuration value or an anonymous
function as a function parameter.
Coding this all inside the function is of course also possible. However,
this would make it much easier to create some specific functions for
which we'd be able to say how the function behaves straight from its own
function and parameters documentation.
--
Edit bug report at https://bugs.php.net/bug.php?id=69028&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69028&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69028&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69028&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69028&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69028&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69028&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69028&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69028&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69028&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69028&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69028&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69028&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69028&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69028&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69028&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69028&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69028&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69028&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69028&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69028&r=mysqlcfg