note 60913 added to function.create-function

From: Date: Fri, 20 Jan 2006 00:43:57 +0000
Subject: note 60913 added to function.create-function
Groups: php.notes 
Request: Send a blank email to php-notes+get-102131@lists.php.net to get a copy of this message
Functions created by create_function() cannot return a value by reference. The function below creates a function that can. The arguments are the same as create_function(). Note that these arguments are passed, unmodified, to eval(), so be sure that data passed in is sanitized. <?php /** * create_ref_function * Create an anonymous (lambda-style) function * which returns a reference * see http://php.net/create_function */ function create_ref_function( $args, $code ) { static $n = 0; $functionName = sprintf('ref_lambda_%d',++$n); $declaration = sprintf('function &%s(%s) {%s}',$functionName,$args,$body); eval($declaration); return $functionName; } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 68.166.30.112 ---- Manual Page -- http://www.php.net/manual/en/function.create-function.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60913 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60913&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60913&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60913&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60913&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60913&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60913&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60913&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60913&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#102131) next »