I am new to threads in PHP and I have a problem with classes extending Thread. I need to store an object given in the constructor parameters into a SplObjectStorage but I am unable to do it. The SplObjectStorage object remains empty even after attaching an object.
When I remove the "extends Thread", it works correctly but I need to use threads.
Here is an example :
<?php
class MyClass extends Thread
{
protected $variable;
public function __constructor($object)
{
$this->variable = new \SplObjectStorage;
$this->variable->attach($object);
$storage = new \SplObjectStorage;
$storage->attach($object);
var_dump($this->variable); // shows empty SplObjectStorage
var_dump($storage); // shows SplObjectStorage with $object inside it
var_dump($object); // shows the object
}
public function run() {}
}
Have you got an idea ? I want $this->variable to be like $storage after the attachment.
Thank you.