O
O
olifem2017-09-15 21:24:23
Slider
olifem, 2017-09-15 21:24:23

Is it possible to write a function to a variable without calling it?

In some modern CMS, I saw something like this: You write
$VARIABLE; what is a function call
? Is it possible to write a function into a variable so that when, for example, $FUNCTION is called, the process is executed $function = $class -> function();
I ask out of curiosity, to improve the readability of the code.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor, 2017-09-15
@egormmm

Implement the __invoke() magic method in the class, and then the class can be called as a function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question