View Single Post
Old 07-02-2009, 04:00 PM   #8 (permalink)
Kalle
The Frequenter
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
Kalle is on a distinguished road
Default

Actually we didn't deprecate create_function() (I however suggested it that we did on IRC), the create_function is horrible, what it internally does is to eval() the code and create a runtime function (named __lambda_func) with a hash returned, so its horrible slow and can easily be injected as theres no protection at the eval.

Closures with 5.3 is however really nicely implemented, they are actually implemented in an object oriented way, meaning that:
PHP Code:
<?php
$closure 
= function() { echo 'Hello'; };
?>
Is the same as:
PHP Code:
<?php
$closure 
= new Closure;

/* Where the Closure class would virtually be populated like */
class Closure
{
    public function 
__invoke()
    {
        echo 
'Hello';
    }
}
?>
Meaning that $closure is actually a virtual object created with some engine magioc, using the new magic method __invoke(). The __invoke() method can also be used on regular objects allowing them to act as callables/closures:

PHP Code:
<?php
class Welcomer
{
    public function 
__invoke($name)
    {
        
printf('Greetings %s from the TalkPHP community'$name);
    }
}

$welcomer = new Welcomer;

$welcomer('Kalle');
$welcomer('Adam');
$welcomer('Peter');
?>
So all in all, Closures are damn sleek and is without doubt my favorite feature of PHP 5.3 =)

As for the Windows stuff, just configure your own Apache and load the PHP dll, takes two minutes and whoop whoop you have it running (but thats just me who does it manually =P)
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote
The Following User Says Thank You to Kalle For This Useful Post:
Orc (07-02-2009)