Edit report at https://bugs.php.net/bug.php?id=64608&edit=1

 ID:                 64608
 Updated by:         larue...@php.net
 Reported by:        j dot doyle133 at gmail dot com
 Summary:            Anonymous Function Dereferencing
-Status:             Assigned
+Status:             Open
 Type:               Feature/Change Request
 Package:            *General Issues
 Operating System:   All
 PHP Version:        5.5.0beta1
 Assigned To:        laruence
 Block user comment: N
 Private report:     N



Previous Comments:
------------------------------------------------------------------------
[2013-04-08 02:48:52] larue...@php.net

there is already a PR about this. https://github.com/php/php-src/pull/301

------------------------------------------------------------------------
[2013-04-07 23:09:05] j dot doyle133 at gmail dot com

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

Reply via email to