Re: lambda()

From: Date: Mon, 05 Jun 2000 20:12:40 +0000
Subject: Re: lambda()
References: 1 2 3 4  Groups: php.dev 
Request: Send a blank email to php-dev+get-20275@lists.php.net to get a copy of this message
At 11:20 05/06/2000, Mark Melvin wrote:
    Can it be saved and stored in a database ?
Not sure what you mean by that one.
    Can it be used to execute user-supplied function (potentially harmful)?
Not unless the user goes through quite a few hoops: - The function names created by create_function (lambda() in its new name) are predictive, but, they're generally a bit useless to the average user, as they begin with a NULL. A dedicated user can find an alternative way of calling them, or 'polluting' their namespace by using function pointers and/or eval(), but I don't think we should care too much about this. - create_function() (lambda() in its new name) will never overwrite an existing function, so I don't think it can be used for any harmful/malicious purposes.
You know, this lambda thing opens a lot of possibilities.
To be quite honest, it was possible to implement this functionality using PHP 3.0 since late 1997: function create_function($args, $stmt) {
        static $i=0;
        $i++;
        $code = "function __lambda_$i($args) { $stmt }";
        eval($code);
} It's less robust/stable, mainly because PHP 4.0 is much more robust by definition, and because the low-level API gives you more room for maneuvering, error checking and functionality, but it'd do the trick. Zeev -- Zeev Suraski <zeev@zend.com> http://www.zend.com/

« previous php.dev (#20275) next »