#47765 [NEW]: __invoke lacks if object is a static property or return
From: biohazard999 at gmx dot at
Operating system: Windows XP SP3
PHP version: Irrelevant
PHP Bug Type: Documentation problem
Bug description: __invoke lacks if object is a static property or return
Description:
------------
If the object to invoke is stored in a static property or is returned by a
static function __invoke will not be called.
Especially for singletons is this extremly missleading.
Either it is an documentation problem or something other is wrong.
Actual documentation:
The __invoke method is called when a script tries to call an object as a
function.
Reproduce code:
---------------
class foo
{
public static $instance = null; //only public for this example
public static function get()
{
if(is_null(self::$instance))
self::$instance = new self;
return self::$instance;
}
public function __invoke($name)
{
echo 'Hello '.$name;
}
}
//1)
foo::get()('World');
//2)
foo::get();
foo::$instance('World');
//3)
$bar = foo::get();
$bar('World');
Expected result:
----------------
1) //Here is the parsing-error partial expected
Hello World
2)
Hello World
3)
Hello World
Actual result:
--------------
1)
Parse error: parse error in test.php on line 23
2)
Notice: Undefined variable: instance in test.php on line 27
Fatal error: Function name must be a string in test.php on line 27
3)
Hello World //Behavior as expected
--
Edit bug report at http://bugs.php.net/?id=47765&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=47765&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=47765&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=47765&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=47765&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=47765&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=47765&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=47765&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=47765&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=47765&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=47765&r=support
Expected behavior: http://bugs.php.net/fix.php?id=47765&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=47765&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=47765&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=47765&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47765&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=47765&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=47765&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=47765&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=47765&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=47765&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=47765&r=mysqlcfg
Thread (4 messages)
- biohazard999 at gmx dot at