note 12673 modified in function.create-function by vrana

From: Date: Tue, 17 Aug 2004 14:55:59 +0000
Subject: note 12673 modified in function.create-function by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79971@lists.php.net to get a copy of this message
for those who want to assign it's own name to a function consider this code: <?php $fname = 'hello'; $func = sprintf(' function %s($v="") { Return "$v<BR>"; } ', $fname ); eval($func); echo $fname('Please print it.... please....'); ?> what it does is, : Creats a function as a string; : Replaces the function name with $fname value; : Converts the string into a REAL php code with eval() : Calls the function using the variable function as declared before ($fname); Simple, isn't it? Can work well as an abstraction layer for portability and/or compatibility purposes Maxim Maletsky maxim@maxim.cx // PHPBeginner.com --was-- for those who want to assign it's own name to a function consider this code: $fname = 'hello'; $func = sprintf(' function %s($v="") { Return "$v<BR>"; } ', $fname ); eval($func); echo $fname('Please print it.... please....'); what it does is, : Creats a function as a string; : Replaces the function name with $fname value; : Converts the string into a REAL php code with eval() : Calls the function using the variable function as declared before ($fname); Simple, isn't it? Can work well as an abstraction layer for portability and/or compatibility purposes Maxim Maletsky maxim@maxim.cx // PHPBeginner.com http://php.net/manual/en/function.create-function.php

« previous php.notes (#79971) next »