Re: Code References

From: Date: Mon, 19 May 2003 13:41:58 +0000
Subject: Re: Code References
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-1709@lists.php.net to get a copy of this message
On Mon, 2003-05-19 at 10:59, Zeev Suraski wrote: > At 16:23 19/05/2003, Sterling Hughes wrote: > >On Mon, 2003-05-19 at 10:47, George Schlossnagle wrote: > > > Excuse my ignorance, but how does this differ from the features offered > > > by create_function? (Other than having nicer aesthetics.) > > > > > > >create_function is runtime for one thing, this would be compile time > >(code reference, doesn't need to be relookedup). And then of course > >there are aesthetics, its incredibly ugly to do anything remotely > >complex with create_function. > > Yikes. I really think create_function is more than enough for what we need > in PHP. Whether or not there's an extra lookup for such an expensive > operation (fcall) should not be the reason to add such a feature. It's a Well, its much more than a lookup, its an eval. Also, I can tell you haven't used create_function that much. Even though I use closures alot (when I program Perl), I stay away from create_function() because its ugly (sorry :) $ref = create_function ('$a, $b', <<<HEREDOC \$c = \$a + \$b; \$d = \$c * \$a; return $\d; HEREDOC;); compared to: $ref = function ($a, $b) { $c = $a + $b; $d = $c + $a; return $d; } And that's in the *simplest* of cases. For anything moderately complex, create_function isn't an option. (Plus you have the eval overhead at runtime, and a function lookup.) What I'm proposing is easier, and also faster. > beast from another family of languages (functional languages), we need a > VERY good reason to introduce it. You can do pretty stuff very easily with > create_function and single quotes or heredocs. > As I said to Wez, function pointers/code references are in virtually every language I know of. Anonymous functions are in Perl, Python, Ruby, LISP and possibly others. -Sterling -- "Nothing is particularly hard if you divide it into small jobs." - Henry Ford

« previous php.internals (#1709) next »