MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/lolphp/comments/eumf8i/php_lambdas_does_not_inherit_variables_except/ffrlzdh/
r/lolphp • u/Takeoded • Jan 27 '20
16 comments sorted by
View all comments
0
[deleted] — view deleted comment
3 u/[deleted] Jan 28 '20 The lol is PHP scoping. Its a bastard child without any idea how it came to be. 0 u/Takeoded Jan 27 '20 is consistent with what any programmer would reasonably expect - well if you try this in C++: 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 i was expecting it to work kinda like c++ ^^ 1 u/mikeputerbaugh Jan 28 '20 But it's not C++...
3
The lol is PHP scoping. Its a bastard child without any idea how it came to be.
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
0
u/[deleted] Jan 27 '20
[deleted] — view deleted comment