ext-pmmpthread
ext-pmmpthread copied to clipboard
Multidimensional array writes don't work on ThreadSafeArray when the target sub-array doesn't exist
<?php
declare(strict_types=1);
$t = [];
$t[0][0] = 1;
$t[0][1] = 2;
var_dump($t);
produces
array(1) {
[0]=>
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
}
vs
<?php
declare(strict_types=1);
$t = new \Threaded();
$t[0][0] = 1;
$t[0][1] = 2;
var_dump($t);
which produces
Notice: Indirect modification of overloaded element of Threaded has no effect in C:\Users\dylan-work\Documents\projects\pocketmine-mp\test2.php on line 25
Notice: Indirect modification of overloaded element of Threaded has no effect in C:\Users\dylan-work\Documents\projects\pocketmine-mp\test2.php on line 26
object(Threaded)#1 (0) {
}
Seems like the real bug is that this check is not firing, because the offset doesn't exist: https://github.com/pmmp/pthreads/blob/fork/src/store.c#L311
On closer inspection this problem could be hard to solve, because BP_VAR_W writes could also be generated by something like threaded->nonExisting[0] = 1, which should not result in automatic property creation. pthreads_store_read() doesn't make any differentiation between property reads and array offset accesses.