TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

RFC: Closures in PHP

8 pointsby mcxxalmost 17 years ago

3 comments

henrywalmost 17 years ago
i would like to see it done more like javascript with un-named function. instead of:<p><pre><code> $replacement = function ($matches) { return str_replace ($matches[1], ' ', '&#38;nbsp;').' '; }; return preg_replace_callback ('/( +) /', $replacement, $text); </code></pre> do:<p><pre><code> return preg_replace_callback ('/( +) /', function ($matches) { return str_replace ($matches[1], ' ', '&#38;nbsp;').' '; }, $text); </code></pre> and also make array_map more like Array.each(e) in js:<p><pre><code> $processed = array_map($array, function($e) { return strtolower($e); }); </code></pre> and all the custom defined functions like usort:<p><pre><code> $processed = usort($array, function($a, $b) { return $a &#62; $b ? 1 : -1; });</code></pre>
评论 #222544 未加载
thwartedalmost 17 years ago
Maybe they can finally remove the reference to "lambda" from the create_function documentation, which is entirely false and blatantly misleading.
rcoderalmost 17 years ago
While I personally think that closures and lexical scoping are desirable feature in any language, this seems a bit like putting lipstick on a pig to me.<p>As a simple wrapper around various C libraries with automatic memory management and higher-level syntax, PHP makes a certain kind of sense, warts and all. As a general-purpose high-level language, I have to wonder exactly what problem it solves that Perl, Ruby, and Python haven't already done better.<p>What do you think the average newbie PHP developer is going to do the first time they encounter a function which closes over a class instance as state, and then returns a lambda?<p>The subtle interplay between reference vs. value calling conventions, PHP's <i>weird</i> scoping rules, and the new 'lexical' keyword seems like a sure source of head-scratching for new developers, too.
评论 #222283 未加载
评论 #222324 未加载