473,511 Members | 15,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Jul 17 '05 #1
3 4656
On 10 Jul 2005 13:11:53 -0700, "elektrophyte" <el**********@yahoo.com> wrote:
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!"
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.
What are "variable functions"?


http://uk.php.net/manual/en/function...-functions.php

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2
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

Jul 17 '05 #3
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.

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2160
by: Rick | last post by:
Hello all. I have an index.php file that has a lot of functions that I wrote. Let's say for the sake of argument that there are 1000 functions of 100 lines each. The index.php file is invoked...
2
1744
by: Peter Albertsson | last post by:
Hi, I have a classname in a variable, and I whish to call a static method on that class, what's the syntax for that? I'm using PHP5. Eg. <?php
15
2505
by: Robin Eidissen | last post by:
What I try to do is to iterate over two variables using template metaprogramming. I've specialized it such that when it reaches the end of a row ot starts on the next and when it reaches the last...
9
5997
by: rnn98 | last post by:
hi, my multithread application, running under solaris box, is crashing eventually. I tried to spot and substitute functions not "thread safe", but I guess my search wasn't good enough. I have put...
1
2347
by: G Fernandes | last post by:
Hi, can someone tell me what the following words mean as per C/clc: 1) token 2) token sequence 3) scalar variable 4) vector
4
11335
by: octavio | last post by:
Hello members of the comp.lang.c newsgroup. Please I need you help on the following one. Compiling the simple code I'm getting this error message. Why ? Please what's the correct type of the fb...
4
1766
by: chuaby | last post by:
Hi May i know is it possible to run a function when we pass in the function name as parameter ? eg retval = functionA(A) but i would like to have something like : varFun = functionA(A)
11
2200
by: gg9h0st | last post by:
i saw a code refactorying onload event listener window.onloadListeners=new Array(); window.addOnLoadListener=function(listener) { window.onloadListeners=listener; } why declare the...
11
2233
by: mfglinux | last post by:
Hello to everybody I would like to know how to declare in python a "variable name" that it is in turn a variable In bash shell I would wrote sthg like: for x in `seq 1 3` do M$i=Material(x)...
0
7252
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7371
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5676
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5077
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1583
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.