PHP curly binding syntax for calling methods using a string

I saw in this SO answer that you can use a string inside curly braces to call a PHP class method to

$player->SayHi();

May be alternative, like:

$player->{'SayHi'}();

My questions:

What is this syntax called in PHP? and what happens if the wrong string is used that does not match the method?

Also, can I use this syntax to call non-classical methods?

I looked at the answers in a related post, and there are only links to PHP callback syntax that doesn't seem to cover the curly brace syntax.

Thank,

+4
source share
2 answers

. , , . , :

$var = 'SayHi';
$player->$var();

:

$player->{'SayHi'}();

. , class, .

+5

PHP

:

function getVarName() 
{ return 'aMemberVar'; } 

print $foo->{getVarName()}; // prints "aMemberVar Member Variable"

.

0

All Articles