note 113090 deleted from functions.anonymous by peehaa
| From: | peehaa@php.net | Date: | Thu, 29 Aug 2013 10:16:17 +0000 |
| Subject: | note 113090 deleted from functions.anonymous by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-196115@lists.php.net to get a copy of this message | ||
Note Submitter: Paul TOTH
----
unfortunately we can not use closures to create Javascript like objects :
<?php
function getObj() {
$name = 'Paul';
return array(
'show' =>
function()
use ($name)
{
echo $name. ' ';
},
'setName' =>
function($value)
use($name)
{
$name = $value;
},
);
};
$o = getObj();
$o['show']();
$o['setName']('TOTH');
$o['show']();
$o.show(); // not supported :(
// output : Paul Paul :((
?>