Click here to get back home

well...don't use any reference variable, how to call this function

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
well...don't use any reference variable, how to call this function Yarco 06-01-2008
Get Chitika Premium
Posted by Yarco on June 1, 2008, 10:07 am
Please log in for more thread options
$stdObject->sayHi = create_function('', 'print "Hi";');

How to call sayHi without do something like:
$sayHi = & $stdObject->sayHi;
$sayHi();

Any good idears?or no idear.

Posted by Egbert Teeselink on June 1, 2008, 10:27 am
Please log in for more thread options
> $stdObject->sayHi =3D create_function('', 'print "Hi";');
>
> How to call sayHi without do something like:
> $sayHi =3D & $stdObject->sayHi;
> $sayHi();
>
> Any good idears?or no idear.

An option is call_user_func($stdObject->sayHi);

It's important to recognise that $stdObject->sayHi simply contains a
string with the new function's name. As such, you don't need the
reference,

$sayHi =3D $stdObject->sayHi;
$sayHi();

will also work. The reason "$stdObject->sayHi();" doesn't work is
syntactical; PHP thinks sayHi is a method of $stdObject, and "variable
functions" only work on literal variables, not on expressions (such as
$stdObject->sayHi) - http://www.php.net/manual/en/functions.variable-functio=
ns.php

-egbert

Similar ThreadsPosted
Call-time pass-by-reference has been deprecated; January 16, 2008, 10:51 am
Pass by reference via 'return' a variable... October 10, 2006, 1:48 pm
reference to a function September 19, 2008, 4:24 pm
how to invoke ReflectionMethod and pass variable by reference as argument? May 30, 2008, 5:01 pm
ASP2PHP Function List Reference January 25, 2006, 12:03 pm
recursive function calling by reference April 5, 2006, 5:47 am
iterate through function arguments by reference August 14, 2006, 6:18 am
Function with reference-passed variabel September 26, 2006, 7:04 am
Passing an array as a reference to a function October 10, 2006, 9:43 am
[HELP] trying to pass by reference to an optional function parameter June 7, 2005, 7:24 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap