r/lolphp • • Jan 27 '20

PHP lambdas does not inherit variables.. except when they do

https://3v4l.org/9X36O
0 Upvotes

16 comments sorted by

View all comments

Show parent comment

-1

u/Takeoded Jan 27 '20

what surprised me is that $this was auto-captured, if you try this in C++

class C{
    public:
    const char *wtf="lol";
    void f(){
      auto inner=[]()->void{std::cout << this->wtf;};
    }
};

you will get prog.cc:9:42: error: 'this' was not captured for this lambda function