note 91949 added to function.create-function

From: Date: Thu, 02 Jul 2009 14:45:31 +0000
Subject: note 91949 added to function.create-function
Groups: php.notes 
Request: Send a blank email to php-notes+get-157829@lists.php.net to get a copy of this message
Just a little toy I thought up, I would like to share. Creates an anonymous function, which let you use a class as a function. In php 5.3 there is support for real functors (trough __invoke): <?php function createFunctor($className){ $content = " static \$class; if(!\$class){ \$class = new $className; } return \$class->run(\$args); "; $f = create_function('$args', $content); return $f; } class test { public function run($args){ print $args; } } $test = createFunctor('test'); $test('hello world'); ?> ---- Server IP: 83.137.20.135 Probable Submitter: 195.241.100.248 ---- Manual Page -- http://www.php.net/manual/en/function.create-function.php Edit -- https://master.php.net/note/edit/91949 Del: integrated -- https://master.php.net/note/delete/91949/integrated Del: useless -- https://master.php.net/note/delete/91949/useless Del: bad code -- https://master.php.net/note/delete/91949/bad+code Del: spam -- https://master.php.net/note/delete/91949/spam Del: non-english -- https://master.php.net/note/delete/91949/non-english Del: in docs -- https://master.php.net/note/delete/91949/in+docs Del: other reasons-- https://master.php.net/note/delete/91949 Reject -- https://master.php.net/note/reject/91949 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#157829) next »