2010-02-23 13:44, Hannes Magnusson skrev:
On Tue, Feb 23, 2010 at 13:07, Keryx Web<webmas...@keryx.se>  wrote:
Re this page:
http://php.net/manual/en/functions.anonymous.php

Closures (as described on that page) in PHP are actually closures.
We already have lambda functions..

Unless scope is inherited a function (anonymous or not) is not a closure.

"Lambda" does not return anything (of value) when I search the manual. Are you refering to create_function()?

That is just another, older and more awkward, way of doing lambda.

Back to the page we are discussing:

This code example...

<?php
echo preg_replace_callback('~-([a-z])~', function ($match) {
    return strtoupper($match[1]);
}, 'hello-world');
// outputs helloWorld
?>

...has no closure in sight at all. Just an anonymous function. Lambda.

It is not until example 3 that we have a closure.

Anyway, using closure as a *synonym* to anonymous function is not correct from a computer science perspective and it is confusing for anyone using both PHP and JavaScript - and who isn't these days?

I think the better way to simply rename the chapter from 'anonymous
functions' to 'closures' - but then we risk people that dont know what
a closure is will never click it.
A *lot* of people that use PHP have no idea what 'closure' is, but a
'anonymous function' sounds interesting to them, hence getting them to
click it and discover closures.

It is especially the newbies I am worried about - it is after all my day job to train them. I do not mind them discovering closures, it is just that they should not be confused about what a closure really is.


--
Keryx Web (Lars Gunther)
http://keryx.se/
http://twitter.com/itpastorn/
http://itpastorn.blogspot.com/

Reply via email to