Re: function by reference

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.          |
`------------------------------------------------------------'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux