3

Possible Duplicate:
What is the difference between a language construct and a “built-in” function in PHP?

I have read that in php programming book "Language construct such asecho()andisset()can not be called through variable function" What is the meaning of it ?

Community
  • 1
  • 1
Ashish
  • 14,295
  • 21
  • 82
  • 127

3 Answers3

5

echo() and isset() (just to pick those exemplary for other PHP language constructs) can't be called in a variable function.

Here comes an example of a variable function.

function foo() {
    echo "foo";
}

$func1 = 'foo';
$func1();        // "foo" will be output

And now let's try with echo:

$func2 = 'echo';
$func2();        // "Fatal error: Call to undefined function echo() on line 10"

That's because echo() isn't a function, but a language construct.

ConcurrentHashMap
  • 4,998
  • 7
  • 44
  • 53
3

Any function in php, whether it is built-in or user function, it all will store in an HashTable in the php internal.

When you call a function, It find the function on the HashTable by function name.

But echo(), isset() isn't function, so it's not exists in the function HashTable. so "Language construct such asecho()andisset()can not be called through variable function"

goosman.lei
  • 386
  • 1
  • 3
  • 7
1

It means you cannot do this:

$f = 'echo';
$f('hello world');

Because echo is not a function (like sprintf for example) but a language symbol (like if for example)

Fabian Schmengler
  • 24,155
  • 9
  • 79
  • 111