Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do variable functions in PHP work?

Tags:

function

php

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(); 
like image 424
user3021621 Avatar asked Jun 12 '26 12:06

user3021621


1 Answers

It means you can’t do something like this:

$var = "echo";
$var "Hello World!";
like image 178
Sharanya Dutta Avatar answered Jun 14 '26 05:06

Sharanya Dutta