# Code References

- Thread: https://externals.io/message/1698
- Original archive: https://news-web.php.net/php.internals/1698
- Started by Sterling Hughes on 2003-05-19T13:16:33+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #1698 — Sterling Hughes — 2003-05-19T13:16:33+00:00

URL: https://externals.io/message/1698#1698

Hi,

I figure I'll just throw this out into the wilderness, I want closures
and function pointers in PHP.  In other words I want the ability to do:

$var = function ($a, $b) {
    return $a + $b;
};

And then $var can contain a code reference to the anonymous function. 
Having code references is an infinitely useful feature in my experience,
and I know other people have some really cool uses of closures for
lightweight templating (with mod_perl.) [1]

I'd also like function pointers, which are optimized callbacks of some
sort, so you can go:

function my_compare($a, $b) {
   if ($a > $b) return 1;
   if ($a < $b) return -1;
   return 0;
}

sort($ar, <my_compare>);

And compare doesn't need to be resolved at runtime, but rather can be a
compile time feature.

-Sterling

[1] I say code references on purpose.  This doesn't need to mean full
fledged closures, which are probably overkill (although, they would be
nice too ;)

-- 
"That stuff's easy compared to installing Horde" 
    - Alan Knowles, In response to my applause for creating a LALR 
    parser for PHP.

---

## #1700 — Sterling Hughes — 2003-05-19T13:18:25+00:00

URL: https://externals.io/message/1698#1700 · In reply to: #1698

> Hi,
> 
> I figure I'll just throw this out into the wilderness, I want closures
> and function pointers in PHP.  In other words I want the ability to do:
> 

^^^^
I meant code references of course.

-Sterling
-- 
"Science is like sex: sometimes something useful comes out, 
but that is not the reason we are doing it." 
    - Richard Feynman

---

## #1702 — Zeev Suraski — 2003-05-19T14:47:20+00:00

URL: https://externals.io/message/1698#1702 · In reply to: #1698

Anything that create_function() doesn't do?

Zeev

At 16:16 19/05/2003, Sterling Hughes wrote:
>Hi,
>
>I figure I'll just throw this out into the wilderness, I want closures
>and function pointers in PHP.  In other words I want the ability to do:
>
>$var = function ($a, $b) {
>     return $a + $b;
>};
>
>And then $var can contain a code reference to the anonymous function.
>Having code references is an infinitely useful feature in my experience,
>and I know other people have some really cool uses of closures for
>lightweight templating (with mod_perl.) [1]
>
>I'd also like function pointers, which are optimized callbacks of some
>sort, so you can go:
>
>function my_compare($a, $b) {
>    if ($a > $b) return 1;
>    if ($a < $b) return -1;
>    return 0;
>}
>
>sort($ar, <my_compare>);
>
>And compare doesn't need to be resolved at runtime, but rather can be a
>compile time feature.
>
>-Sterling
>
>[1] I say code references on purpose.  This doesn't need to mean full
>fledged closures, which are probably overkill (although, they would be
>nice too ;)
>
>--
>"That stuff's easy compared to installing Horde"
>     - Alan Knowles, In response to my applause for creating a LALR
>     parser for PHP.

---

## #1701 — George Schlossnagle — 2003-05-19T14:47:45+00:00

URL: https://externals.io/message/1698#1701 · In reply to: #1698

Excuse my ignorance, but how does this differ from the features offered 
by create_function?  (Other than having nicer aesthetics.)




> Hi,
>
> I figure I'll just throw this out into the wilderness, I want closures
> and function pointers in PHP.  In other words I want the ability to do:
>
> $var = function ($a, $b) {
>     return $a + $b;
> };
