View Single Post
Old 07-02-2009, 12:22 AM   #1 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default Anonymous Functions in PHP 5.3.0, deprecates create_function

I've seen in PHP 5.3.0 which has been recently released, allows for anonymous functions assigned to variables, so instead of doing this:

Example #1
PHP Code:
function Add($a,$b) { return $a $b; }

$A 'Add';
$var1 2;
$var2 2;

printf('%d'$A($var1,$var2)); 
Example #2
PHP Code:

$A 
create_function('$args''return $args[0] + $args[1];');

printf('%d'$A(2,2)); 

We can do:
PHP Code:
$A = function($a$b) {
 return 
$a $b;

which I like this a lot, reminds me a lot like javascript, i hope this can be done with classes aswell, like so:
PHP Code:

$A
::MyMethod = public static function( $a$b ) { return $a b; } 
On-Topic about PHP 5.3 aswell, I tried to install it on xampp, but I still happen to get a parse error by trying to do the simplest of putting in "namespace Project;". even though the module is loaded in apache ( at least in the config )
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote