call_user_func() vs. "variable functions"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • elektrophyte

    call_user_func() vs. "variable functions"

    I was looking at the PHP function "call_user_func ()"
    (http://us3.php.net/call_user_func). It appears that this will solve a
    design problem in the app I'm working on. (I'm writing a class that
    will allow a PHP programmer to call their own custom functions.)

    However, in the comments a couple people mention "variable functions".
    E.g., "You should avoid this function and use variable function calls
    instead!"

    What are "variable functions"?

    Thanks,

    E

  • Andy Hassall

    #2
    Re: call_user_func( ) vs. "variab le functions"

    On 10 Jul 2005 13:11:53 -0700, "elektrophy te" <elektrophyte@y ahoo.com> wrote:
    [color=blue]
    >I was looking at the PHP function "call_user_func ()"
    >(http://us3.php.net/call_user_func). It appears that this will solve a
    >design problem in the app I'm working on. (I'm writing a class that
    >will allow a PHP programmer to call their own custom functions.)
    >
    >However, in the comments a couple people mention "variable functions".
    >E.g., "You should avoid this function and use variable function calls
    >instead!"[/color]

    They're quite similar, and the choice probably just comes down to an opinion
    on style.

    However, call_user_func_ array has distinct advantages, such as not needing to
    know the number of parameters in advance.
    [color=blue]
    >What are "variable functions"?[/color]



    --
    Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
    <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

    Comment

    • elektrophyte

      #3
      Re: call_user_func( ) vs. &quot;variab le functions&quot;

      Oh so that's what "variable functions" are. It's funny, I searched but
      that didn't come up. It's a cool piece of language functionality, but
      it looks like it could lead to some really hard-to-read code. I think
      I'll use the more verbose, but clearer "call_user_func ()" method.

      E

      Comment

      • Chung Leong

        #4
        Re: call_user_func( ) vs. &quot;variab le functions&quot;

        Functionally the two methods are the same. They differ in how PHP
        reacts when the specified function is undefined. Calling a non-existing
        function through a variable causes a fatal error, while
        call_user_func( ) returns a warning.

        Comment

        Working...