Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

Changed closure scope #605

Closed
sirsnyder opened this issue Jun 24, 2016 · 3 comments
Closed

Changed closure scope #605

sirsnyder opened this issue Jun 24, 2016 · 3 comments

Comments

@sirsnyder
Copy link
Collaborator

This is not really a bug report, it's more an info.

Since php 7.0.7 the scope of closures has been changed. This has an impact to the use of synchronize().

example

class Test extends Threaded
    {
        protected $data;

        public function __construct()
        {
            $this->data = new Threaded();
        }

        public function work()
        {
            $this->data->synchronized(function()
            {
                // <= 7.0.6 - $this = class scope
                $this->data->wait();

                // >= 7.0.7 - $this = scope of threaded object $data
                $this->wait();
            });
        }
    }

    $test = new Test();
    $test->work();

Tested on Windows 7 x64, pthreads 3.1.6, php 7.0.3 - 7.0.8. Also mac(?) with pthreads master and php 7.0.8

@sirsnyder
Copy link
Collaborator Author

sirsnyder commented Aug 4, 2016

Hi @krakjoe,

I have to withdraw my first statement. It is a bug. I'm unable to find an easy workaround or another simple solution.

class Test extends Threaded
    {
        protected $data;

        public function __construct()
        {
            $this->data = new Threaded();
        }

        public function work()
        {
            $func = function()
            {
                var_dump($this);
            };
            $func();

            $this->data->synchronized($func);
        }
    }

    $test = new Test();
    $test->work();

Result

object(Test)#1 (1) {
   ["data"]=>
   object(Threaded)#2 (0) {
   }
 }
 object(Threaded)#2 (0) {
 }

Expected

object(Test)#1 (1) {
   ["data"]=>
   object(Threaded)#2 (0) {
   }
 }
 object(Test)#1 (1) {
   ["data"]=>
   object(Threaded)#2 (0) {
   }
 }

Tested on Windows 7 x64, php 7.0.9 and pthreads 3.1.6.

Thx and regards

@krakjoe
Copy link
Owner

krakjoe commented Dec 22, 2016

Try that please ...

@krakjoe
Copy link
Owner

krakjoe commented Jan 1, 2017

I'm sure this was fixed by the commit referenced, so closing ... if I'm wrong please open a new report ...

Thanks ;)

@krakjoe krakjoe closed this as completed Jan 1, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants