Re: function by reference

From: Date: Mon, 10 Apr 2006 16:25:14 +0000
Subject: Re: function by reference
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-233673@lists.php.net to get a copy of this message
On Mon, 2006-04-10 at 09:42, tedd wrote: > >It's the same thing for the most part... > > > ><?php > > > >$a = 'f_a'; > >call_user_func( $a, $p1, $p2, $p3 ) > > > >?> > > > >Cheers, > >Rob. > > Rob: > > No way dude -- that was too easy! > > Boy, am I in love with this language -- it gives you plenty of > shovels to dig yourself in as deep as you want. *lol*. personally I prefer the other format which was what I tried to illustrate with my original example: <?php $a = 'f_a'; $a( $p1, $p2, $p3 ); ?> All it means, is that once you have the name of a function in a variable you can invoke the variable as a function and it will invoke the function matching the variable's value. Some of this stuff can be really useful for doing backwards compatibility with older versions of PHP: <?php function my_slowass_ctype_alpha( $chars ) { return eregi( '^[[:alpha:]]+$, $chars ); } if( function_exists( 'ctype_alpha' ) ) { $ctype_alpha = 'ctype_alpha'; } else { $ctype_alpha = 'my_slowass_ctype_alpha'; } if( $ctype_alpha( 'weeeeee' ) ) { echo 'Alpha chars only!'; } else { echo 'Not alpha chars only!'; } ?> Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------'

« previous php.general (#233673) next »