M
M
Maxim Ivanov2015-09-29 20:54:15
PHP
Maxim Ivanov, 2015-09-29 20:54:15

How to access a class function if there is only its key?

Let's say I have

$func = 'namefunction';
class A {
  public namefunction(){
   echo 1;
  }
}

a = new A;

// возможно ли как-то придумать такой способ обращения, или есть что-то на этот счет?
a->[$func](); // a->'namefunction'();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HaruAtari, 2015-09-29
@omaxphp

You all think right. Only it is necessary to use not square, but curly brackets.
In general, it is possible without brackets, but it turns out more clearly with them.
And yet, you have a amissing sign in front$

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question