From:             bar105 at zepler dot net
Operating system: Linux
PHP version:      5.2.10
PHP Bug Type:     Scripting Engine problem
Bug description:  Type hinted parameter default value cannot be a class 
constant defined as null

Description:
------------
The parser does not permit the use of a class constant with the value NULL
as a default value for a type-hinted function parameter.

Using class constants instead of specific values such as "NULL" promotes a
cleaner API, and more easily readable code. 


consider the following function, which might retrieve data from a database
either for a specific date or for all dates:
$foo->getInfo(Date::today());

// If given null, retrieve for all dates
$foo->getInfo(null);

// Using a class constant is much more readable
$foo->getInfo(Foo::ALL_DATES);


The parser should, imho, resolve the value of class constants before
throwing an error stating the default value is not NULL and therefore not
permitted.

Please consider correcting this behaviour.

Reproduce code:
---------------
class Foo {
    const NO_VALUE = null;

    public static function bar(Foo $param = self::NO_VALUE) {
        if ($param == self::NO_VALUE)
            echo "Param was NO_VALUE"
        else
            echo "Param was a valid instance of Foo";
    }
}

Expected result:
----------------
$myFoo = new Foo();

Foo::bar(my$Foo);
// "Param was a valid instance of Foo"

Foo::bar();
// "Param was NO_VALUE"

Actual result:
--------------
Fatal error: Default value for parameters with a class type hint can only
be NULL

-- 
Edit bug report at http://bugs.php.net/?id=49233&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=49233&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=49233&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=49233&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=49233&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=49233&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=49233&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=49233&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=49233&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=49233&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=49233&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=49233&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=49233&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=49233&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=49233&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=49233&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=49233&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=49233&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=49233&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=49233&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=49233&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=49233&r=mysqlcfg

Reply via email to