note 77773 added to function.create-function

From: Date: Wed, 12 Sep 2007 16:16:26 +0000
Subject: note 77773 added to function.create-function
Groups: php.notes 
Request: Send a blank email to php-notes+get-130419@lists.php.net to get a copy of this message
How about creating pseudo lambda technique like below? ------------------- sample.php ------------------ <?php ob_start(); ?> static $c = 0; $c++; return $a + $b + $c; <?php $_code = ob_get_contents(); ob_end_clean(); $lambda = create_function('$a, $b', $_code); echo $lambda(1, 2)."\n"; echo $lambda(3, 4)."\n"; ?> ------------------------------------------------- It will be: $ php hoge3.php 4 # 1($a) + 2($b) + 1($c++) 9 # 3($a) + 4($b) + 2($c++) In normal usage, special chars escapement (like ', ", \) is messy for me and leads many syntax errors! But above technique, source is more readable and we don't need to pay attention escapement any more. Regards, request for comments. ---- Server IP: 61.195.146.164 Probable Submitter: 219.101.94.15 ---- Manual Page -- http://www.php.net/manual/en/function.create-function.php Edit -- https://master.php.net/note/edit/77773 Del: integrated -- https://master.php.net/note/delete/77773/integrated Del: useless -- https://master.php.net/note/delete/77773/useless Del: bad code -- https://master.php.net/note/delete/77773/bad+code Del: spam -- https://master.php.net/note/delete/77773/spam Del: non-english -- https://master.php.net/note/delete/77773/non-english Del: in docs -- https://master.php.net/note/delete/77773/in+docs Del: other reasons-- https://master.php.net/note/delete/77773 Reject -- https://master.php.net/note/reject/77773 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#130419) next »