ID:               49233
 User updated by:  bar105 at zepler dot net
 Reported By:      bar105 at zepler dot net
 Status:           Open
 Bug Type:         Scripting Engine problem
 Operating System: Linux
 PHP Version:      5.2.10
 New Comment:

In the expected result, "my$Foo" should read "$myFoo".


Previous Comments:
------------------------------------------------------------------------

[2009-08-12 10:53:54] bar105 at zepler dot net

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 this bug report at http://bugs.php.net/?id=49233&edit=1

Reply via email to