From:             j dot doyle133 at gmail dot com
Operating system: All
PHP version:      5.5.0beta1
Package:          *General Issues
Bug Type:         Feature/Change Request
Bug description:Anonymous Function Dereferencing

Description:
------------
The anonymous functions wouldn't really be complete without dereferencing,
making 
it easier for developers to split their code up into chunks, and having one
return  
value. Database calls that are only going to be called once for example,
but need 
to be stored in an array. There's no point making a whole function for it
and no 
point setting it to a variable to be run once.

Test script:
---------------
$my_array = [
    'key_1' => function() {
         return mt_rand();
    }(),

    'database' => function() {
        $db  = new PDO("mysql:host=127.0.0.1; port=3306;", "root", "");
        $sth = $db->prepare("SELECT * FROM `users` WHERE `username`=? LIMIT
1");
        $sth->bindParam(1, 'Test');
        $sth->execute();
        return $sth->fetch(PDO::FETCH_ASSOC);
    }()
];

Expected result:
----------------
An array with two values, a random value on 'key_1' and an associative
array on 
'database'.

Actual result:
--------------
Parse error: syntax error, unexpected '(', expecting ']' in php shell code
on line 
4

When leaving out the parentheses; two closure classes.

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

Reply via email to