The reason you are not allowed to use references, even to types that do not require serialization, is that there would be no opportunity to provide safety if you were allowed to do that ...
Consider the following:
$this->member = $data;
Currently, this is an atomic write to the Threaded object, and this:
$data = $this->member;
an atomic read.
If these actions were not atomic, consider that if some other thread calls the first example of code while another thread is calling the second, $data
would be garbage at best and generate a fault at worst.
Consider that if references were allowed and the following code worked:
$data =& $this->member;
The context with a reference to data would be allowed to break safety, with no opportunity to intervene, it would be extremely hard to program with threads in this way.
The beauty of a high level threading API is that you do not have to worry so much about safety, it is provided for you, don't seek out ways to break that safety has to be good advice.
All Threaded objects behave as if they are an array, with utility methods like pop and operators installed so that they can be treated as an array by your code.
Threaded objects are not serialized, they are safe, you still cannot use references, but nor do you need too:
<?php
class Shared extends Threaded {}
class Appender extends Thread {
public function __construct(Shared $shared) {
$this->shared = $shared;
}
public function run() {
while (count($this->shared) < 1000) {
$this->shared[] =
count($this->shared);
}
}
protected $shared;
}
class Shifter extends Thread {
public function __construct(Shared $shared) {
$this->shared = $shared;
}
public function run() {
while(count($this->shared)) {
var_dump($this->shared->shift());
}
}
}
$shared = new Shared();
$appender = new Appender($shared);
$shifter = new Shifter($shared);
$appender->start();
$shifter->start();
$appender->join();
$shifter->join();
?>
The code above shares an object of class Shared between two other threads, as a simple example, one thread is pushing and another shifting from the same array, safely.
This example code isn't meant to be a good example of anything other than using Threaded objects as if they are arrays.