I have the following code where I'm attempting to assign a value to an array in a class that uses php pthreads to no avail - I have looked at solutions that suggest using stacks to no avail either:
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL);
class WorkerThreads extends Thread
{
private $fromlist;
public function __construct()
{
$this->fromlist = array();
}
public function run()
{
$this->fromlist=array("hello"=>1,2);
$this->fromlist['hi']="!!!";
$this->fromlist[] = array("ho", 1);
}
}
$workers = new WorkerThreads();
$workers->start();
print_r($workers);
I get the following results:
WorkerThreads Object
(
[fromlist] => Array
(
[hello] => 1
[0] => 2
)
)
I was expecting to see additional array elements - try as I may I cannot get it to add more elements.
I've checked the syntax and it seems fine - the problem appears to be how to use an array in pthreads - I can't seem to make sense of how to do that.
Can anyone tell me what I'm doing wrong?
Or suggest some code for the above so I can get to a working solution?
Adding the $fromlist variable to the run() function solves the problem.