I'm trying to run some code asynchronously within my class (see: https://github.com/duncan3dc/fork-helper). I need to call a series of methods that will modify the values of my properties. I can't seem to do so. I'm trying to use the last example of the call() method on this page: https://duncan3dc.github.io/fork-helper/usage/getting-started/
<?php
class foobar
{
private $x = 0;
public function doubler(&$number_to_double)
{
$number_to_double = $number_to_double * 2;
}
public function index()
{
$fork = new \duncan3dc\Forker\Fork;
$this->x = 5;
// outputs 5, as expected
var_dump($this->x);
$fork->call([$this, 'doubler'], $this->x);
$fork->wait();
// does not output 10, which is what I want
var_dump($this->x);
}
}
$my_foobar = new foobar();
$my_foobar->index();
I don't have to pass by reference, like I did in my doubler
. Instead, I'm also open to just modifying the member from within the doubler
method.
Why isn't my private member x
doubling at the second var_dump()
?