3

In php.net the following is written:

Variable functions won't work with language constructs such as echo, print, unset(), isset(), empty(), include, require and the like. Utilize wrapper functions to make use of any of these constructs as variable functions.

source

What does that mean?
Could anyone give examples because I’ve tried using the variable function in an echo and it worked perfectly:

function city()
{
    return "new york";
}
$var = "city";
echo "city:  "  . $var(); 

3 Answers 3

11

It means you can’t do something like this:

$var = "echo";
$var "Hello World!";
Sign up to request clarification or add additional context in comments.

2 Comments

+1 Ding ding ding! :-D
The comment about wrapper functions means you /can/ do something like this: function myecho($str) { echo $str; } $var = "myecho"; $var("Hello world!");
0

You cannot do that with these functionns echo, print, unset(), isset(), empty() because actualy in php they are not functions, they are reserved keywords with functions call like.

Comments

-1

Correct Way is

function city()
{
    return "new york";
}
$var = "city";
echo "city:  "  . city(); 

It will Return :

city: new york

1 Comment

This answer is not helpful and you've completed negated the purpose in setting $var.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.