I've been stuck on this for a while and am not sure of the problem.
Maybe someone here might have some good insight?
Here is the 'code':
class File extends Stackable{
private $data;
function set_data($array){
foreach($array as $row => $data)
foreach($data as $col => $val)
$this->data[$row][$col]=$val;
echo $this->data[$row][$col];
}
}
In which it states that on the echo
there is an Undefined index : $col
, where $col
is generally a letter.
$row
can be assumed to be set.
Maybe I'm not providing enough details, and its possible that there may be other dependencies, if so please let me know.
One thing of note is the use of php pthreads here, though i don't believe it is the cause, since the error still happens with 1 thread.
Thank you in advance for any help.
The member "data" is just a normal array, your are loosing dimensions because of the way pthreads objects work; you don't want to use the member "data", it is not necessary:
<?php
class File extends Stackable {
/* in pthreads you are responsible for the objects you create */
/* so we accept an array by reference to store dimensions */
public function set_data($array, &$files){
foreach($array as $row => $data) {
foreach($data as $col => $val) {
/* force this vector into existence */
if (!isset($this[$row])) {
$this[$row] = $files[] = new File();
}
$this[$row][$col]=$val;
}
}
}
public function run() {}
}
$files = array();
$f = new File();
$f->set_data(array("test" => array($_SERVER)), $files);
var_dump($f);
?>
You should bear in mind that pthreads objects have the overhead of safety to contend with, so loop over their members as little as possible, in an ideal world, the $array coming to setData would already be of a suitable type ...