473,385 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

address of functions


Is it possible to store the address or reference to a function in php? Maybe
using just a string and later dereferencing it?

e.g some ideas to illustrate what I mean

<?php
function myCompanyMotto(){
echo "hello";
}

$myarr["func1"]=&myCompanyMotto;
$myarr["func2"]="myCompanyMotto";

//how to get function from myarr and call it????

?>
--
Feb 20 '07 #1
3 1296
Rik
On Tue, 20 Feb 2007 22:53:14 +0100, Richard <rg****@gmail.comwrote:
>
Is it possible to store the address or reference to a function in php?
Maybe
using just a string and later dereferencing it?

e.g some ideas to illustrate what I mean

<?php
function myCompanyMotto(){
echo "hello";
}

$myarr["func1"]=&myCompanyMotto;
$myarr["func2"]="myCompanyMotto";

//how to get function from myarr and call it????

?>
I'd just use call_user_func()/call_user_func_array(), and save the
callback either as a string for normal functions, and as an array for
object/class methods.

function myCompanyMotto(){
echo "hello";
}
class foo{
function bar(){
echo 'class';
}
}
$myarr['func1'] = 'myCompanyMotto';
$myarr['func2'] = array('foo','bar');
call_user_func($myarr['func1']);
call_user_func($myarr['func2']);
--
Rik Wasmus
Feb 20 '07 #2
Rik <lu************@hotmail.comwrites:
On Tue, 20 Feb 2007 22:53:14 +0100, Richard <rg****@gmail.comwrote:
>>
Is it possible to store the address or reference to a function in
php? Maybe
using just a string and later dereferencing it?

e.g some ideas to illustrate what I mean

<?php
function myCompanyMotto(){
echo "hello";
}

$myarr["func1"]=&myCompanyMotto;
$myarr["func2"]="myCompanyMotto";

//how to get function from myarr and call it????

?>

I'd just use call_user_func()/call_user_func_array(), and save the
callback either as a string for normal functions, and as an array for
object/class methods.

function myCompanyMotto(){
echo "hello";
}
class foo{
function bar(){
echo 'class';
}
}
$myarr['func1'] = 'myCompanyMotto';
$myarr['func2'] = array('foo','bar');
call_user_func($myarr['func1']);
call_user_func($myarr['func2']);
Thanks, I had googled, but being new to PHP I hadnt found
call_user_func. Just what I want.
Feb 20 '07 #3
"Richard" <rg****@gmail.comwrote in message
news:87************@gmail.com...
>
Is it possible to store the address or reference to a function in php?
Maybe
using just a string and later dereferencing it?

e.g some ideas to illustrate what I mean

<?php
function myCompanyMotto(){
echo "hello";
}

$myarr["func1"]=&myCompanyMotto;
$myarr["func2"]="myCompanyMotto";

//how to get function from myarr and call it????

function foo(){
echo "Hello Kitty!";
}

$bar = 'foo';

$bar();
--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Feb 21 '07 #4

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

Similar topics

7
by: Nolan Martin | last post by:
is a static functions address constant? ie.. static void func(); write_to_file(&func); Restart program... static void func(); void (*funcPtr) ();
12
by: johny smith | last post by:
I am trying to figure out a way to print the address of what called a certain function once inside the function. I am assuming that this information is on the stack somewhere. But can someone...
35
by: hasho | last post by:
Why is "call by address" faster than "call by value"?
89
by: Sweety | last post by:
hi, Is main function address is 657. its show in all compiler. try it & say why? bye,
7
by: salmonella | last post by:
Hi, I'm trying to print on screen an address of class member function (the function of certain object of course). My code looks like this: class MyClass { public: void fun(void){}; };
2
by: first10 | last post by:
Hello, Apologies for being slightly off topic - but this group seems the best fit for the question. How does the compiler handle the problem of not knowing which address a DLL will be loaded...
6
by: Todd A. Anderson | last post by:
I have a function foo of which I need to get the address. The problem is that when you say "&foo" (or just foo for that matter), you get the address of this function's entry in a jump table and...
5
by: wright.brandt | last post by:
I am new to programming in C. If my question is not appropriate for this newsgroup I apologize. I Have been tasked with writing a small application to do some back end processing in C and have had...
7
by: Ancient_Hacker | last post by:
In days of old, for no discernible reason, many CPU's had the ability to execute one or more instructions out of registers. Not very common today. Which brings up a semi interesting point. ...
13
by: bob the builder | last post by:
Can i get the class of an object of which i only have the address? Lets say i have 3 classes: AClass,BClass,CClass. i also have an object of each class: aObject, bObject, cObject And finally i...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...

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.