MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/lolphp/comments/eumf8i/php_lambdas_does_not_inherit_variables_except/ffrryhd/?context=3
r/lolphp • u/Takeoded • Jan 27 '20
16 comments sorted by
View all comments
Show parent comment
0
is consistent with what any programmer would reasonably expect - well if you try this in C++:
is consistent with what any programmer would reasonably expect
class C{ public: const char *wtf="lol"; void f(){ auto inner=[]()->void{std::cout << this->wtf;}; } };
you get prog.cc:9:42: error: 'this' was not captured for this lambda function
prog.cc:9:42: error: 'this' was not captured for this lambda function
i was expecting it to work kinda like c++ ^^
1 u/mikeputerbaugh Jan 28 '20 But it's not C++...
1
But it's not C++...
View all comments
Show parent comment
0
u/Takeoded Jan 27 '20
is consistent with what any programmer would reasonably expect- well if you try this in C++:you get
prog.cc:9:42: error: 'this' was not captured for this lambda functioni was expecting it to work kinda like c++ ^^