TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-01-2009, 11:22 PM   #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
Old 07-01-2009, 11:49 PM   #2 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

Quote:
Originally Posted by Orc View Post


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 )

You have to wait for xampp to release an update, the module still needs to be coded into the program, thats why..
codefreek is offline  
Reply With Quote
Old 07-02-2009, 04:43 AM   #3 (permalink)
The Contributor
 
ryanmr's Avatar
 
Join Date: Jun 2008
Location: Twin Cities, Minnesota, USA
Posts: 44
Thanks: 3
ryanmr is on a distinguished road
Default

Now that 5.3.0 has been released, what do you think the Host penetration time will be? As in, how long do you think it will take for shared hosts to update their PHP version?

I have 1and1 and I don't think they'll be fast about updating anything.
__________________
blog twitter ifupdown
ryanmr is offline  
Reply With Quote
Old 07-02-2009, 09:28 AM   #4 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by ryanmr View Post
Now that 5.3.0 has been released, what do you think the Host penetration time will be? As in, how long do you think it will take for shared hosts to update their PHP version?

I have 1and1 and I don't think they'll be fast about updating anything.
It probably won't be but for a very long time. :P But I'm really looking forward to namespaces, it's one of those things I wanted in PHP, that I always seemed to need. plus it stops those people from whining about how php isnt really a language without namespaces ;p
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 07-02-2009, 03:09 PM   #5 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

Quote:
Originally Posted by ryanmr View Post
Now that 5.3.0 has been released, what do you think the Host penetration time will be? As in, how long do you think it will take for shared hosts to update their PHP version?

I have 1and1 and I don't think they'll be fast about updating anything.

Ryanmr, you should be able to request your host to update,
or at least ask how long it will take for them to update,
big hosting companies will make an update soon if, they already
haven't done it, like godaddy.com i think is already done with updates..
codefreek is offline  
Reply With Quote
Old 07-02-2009, 09:25 AM   #6 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by codefreek View Post
You have to wait for xampp to release an update, the module still needs to be coded into the program, thats why..
But I had installed VC6 Thread safe..
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 07-02-2009, 10:44 AM   #7 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Something quite cool is also the use keyword. I don't know if it's specifically for the anonymous functions, but it's great 'cause then you can pass in variables into functions that you need, but don't want to pass as a param when calling the function.

PHP Code:

$db 
= new DB();

$connect = function($host$user$pass) use($db) {

$db->connect($host$user$pass);

}

$connect('localhost''root'''); 
__________________
Tanax is offline  
Reply With Quote
The Following 2 Users Say Thank You to Tanax For This Useful Post:
codefreek (07-02-2009), Orc (07-02-2009)
Old 07-02-2009, 11:22 AM   #8 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

I think use will also be used to specify which namespaces you're wanting to use. I like that feature in anonymous functions!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 07-02-2009, 03:00 PM   #9 (permalink)
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)
Old 06-03-2010, 04:51 AM   #10 (permalink)
The Wanderer
 
Join Date: Mar 2010
Posts: 8
Thanks: 0
infonama is on a distinguished road
Default

i am having the same problem.
__________________
Latest News
Download Free Songs
infonama is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
10 PHP Myths Dispelled Wildhoney General 9 06-15-2009 06:55 AM
PHP Compressor Kalle Script Giveaway 8 05-28-2008 12:14 AM
what are all the subjects in php? sarmenhb General 7 01-21-2008 05:41 PM
Tutorial: PHP and OOP, a beginners guide Village Idiot Tips & Tricks 0 09-06-2007 04:23 PM


All times are GMT. The time now is 06:07 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design