Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69678 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 38646 invoked from network); 18 Oct 2013 13:02:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Oct 2013 13:02:40 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.180 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.180 mail-wi0-f180.google.com Received: from [209.85.212.180] ([209.85.212.180:53497] helo=mail-wi0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 58/E2-23638-F6131625 for ; Fri, 18 Oct 2013 09:02:40 -0400 Received: by mail-wi0-f180.google.com with SMTP id ey11so952377wid.7 for ; Fri, 18 Oct 2013 06:02:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=XIxCU1+mHXQQT7s1e7nuIKkmW42Tq6S1muxBzq7eS5U=; b=1DnSD/g1S886NBo0mUQIQJr91UATVENScNvg/hNHNptG4rcc7TuvkxoOTcbZGfEBIn qK9ThPkBEEsfcs/psDkfVlGCIMhWTfpeS+ZIYxIpOuzsF/NMCU9i1MXfcHmaNpK0GkUd kNSvtXs/PHRDGliTbPuF4lFmG7UJqoKor99p6JXS1cywi1vNGoTmwuS/6lSAA1aByTLs w3iuqz0YUjXGKPlTJwnKi0zyv+XUtPur9BrdLPep4chCkbcqLeR8rbNBWGCWV/Avm75r W6rz3gd/N034KMgDbNFZTbnDwYYu8c+zPKuxutxIv8Xs9grHWs7xXrnQM61xp2NenAte qzaA== X-Received: by 10.180.187.236 with SMTP id fv12mr2948306wic.20.1382101356970; Fri, 18 Oct 2013 06:02:36 -0700 (PDT) Received: from [192.168.0.2] (cpc19-brig17-2-0-cust25.3-3.cable.virginmedia.com. [81.101.201.26]) by mx.google.com with ESMTPSA id ft19sm3341392wic.5.2013.10.18.06.02.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 18 Oct 2013 06:02:36 -0700 (PDT) Message-ID: <52613165.8060001@gmail.com> Date: Fri, 18 Oct 2013 14:02:29 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 MIME-Version: 1.0 To: internals@lists.php.net References: <525C631E.1050008@gmail.com> <52610FFE.7020806@googlemail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Proposal to deprecate create_function() From: rowan.collins@gmail.com (Rowan Collins) On 18/10/2013 13:39, Ferenc Kovacs wrote: > I've only skimmed through the thread, but did somebody already proposed > changing the return value of create_function to return a closure instead of > deprecating it? I mentioned it briefly in my initial post, but felt that unless BC was 100%, it wasn't worth it, as you couldn't guarantee which of the current behaviour people were relying on. People can always write a version in PHP which is good enough for their particular requirements. > If we really we want 100% compatibility, we could even add a __toString to > the Closure object with an internal function name (similar was proposed by > Joe for anonymous functions and I listed it as a con, because not matching > the current behaviors of Closures) through which it can be called as a > string while throwing a STRICT/DEPRECATED error so people can move away > from manipulating the return value as a string, and we can remove that > behavior later on. That's an interesting idea, although I'm not sure about adding a feature and immediately deprecating it. It seems like if closures had a __toString, people would start to use it, so we would have to assume that the feature was there to stay. Another thought I had was to implement a safer version of create_function() under a different name, and provide a PHP-level implementation which ran under old versions for forwards-compatibility. You could, for instance, take an associative array of variables to close over, which would be equivalent to the use() statement if implementing on top of closures, and use var_export() to interpolate into a legacy create_function() implementation: usort( $some_array, create_eval_closure( // args, as name only; would lack of default value support be a problem? array('a', 'b'), // function body, as a static string 'return strcasecmp($a[$key], $b[$key]);', // variables to "close over" array('key' => $key) ) ); Basically, it would be a bit like a parameterised SQL query: you can't actually prevent people interpolating into the strings anyway, but you can give them a safe mechanism that means they shouldn't need to. -- Rowan Collins [IMSoP]