neoform Posted January 10, 2008 Share Posted January 10, 2008 Is it possible to pass unnamed functions or classes? e.g. $func = function($param1, $param2) { echo "hi"; } or $obj = new class { ... } Quote Link to comment https://forums.phpfreaks.com/topic/85456-unnamed-classesfunctions/ Share on other sites More sharing options...
teng84 Posted January 10, 2008 Share Posted January 10, 2008 for what? Quote Link to comment https://forums.phpfreaks.com/topic/85456-unnamed-classesfunctions/#findComment-436068 Share on other sites More sharing options...
Ken2k7 Posted January 10, 2008 Share Posted January 10, 2008 I'm a bit confused and your question isn't clearly stated. So I'm guessing you want a variable to contain a function or class? Is that your question? Quote Link to comment https://forums.phpfreaks.com/topic/85456-unnamed-classesfunctions/#findComment-436072 Share on other sites More sharing options...
trq Posted January 11, 2008 Share Posted January 11, 2008 <?php $func = create_function('$s', 'echo $s'); $func('hi'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/85456-unnamed-classesfunctions/#findComment-436088 Share on other sites More sharing options...
neoform Posted January 11, 2008 Author Share Posted January 11, 2008 Hmm, that's probably not very efficient though, I guess php doesn't have a real way to work with unnamed functions.. Quote Link to comment https://forums.phpfreaks.com/topic/85456-unnamed-classesfunctions/#findComment-436280 Share on other sites More sharing options...
Ken2k7 Posted January 11, 2008 Share Posted January 11, 2008 What are you trying to do that requires that? Quote Link to comment https://forums.phpfreaks.com/topic/85456-unnamed-classesfunctions/#findComment-436285 Share on other sites More sharing options...
neoform Posted January 11, 2008 Author Share Posted January 11, 2008 I'd like to pass a function as a variable without having to give it a dynamic name since there are multiple parallel queries with similar code (modules). This is something that gets done often in C++ but appears no possible in php.. Quote Link to comment https://forums.phpfreaks.com/topic/85456-unnamed-classesfunctions/#findComment-436391 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.