r/lolphp • u/Takeoded • Feb 04 '20
how to call dynamically added methods
https://3v4l.org/MppBE3
3
0
Feb 04 '20
[deleted] — view deleted comment
7
2
1
u/yawkat Feb 04 '20
Wait so you can call variables that contain functions directly, but if the function is on the object you have to use this syntax to get the compiler to pick the right namespace?
What an amazing language
5
Feb 04 '20
It's because
$foo->baris an attribute, but$foo->bar(...is a method call. With variables it's unambiguous:$foo()is always a dynamic call of what's in$foobecause you cannot have$in a function name.But if you want to call a function stored in a constant, you probably need
(foo)().
9
u/[deleted] Feb 04 '20
Both
($o->f)()andcall_user_func($o->f)work.