我正在编写一个将信息提供给容器类的函数。我一直收到错误Attempt to modify property of non-object in
。涉及到很多课程,如果有人愿意总共查看整个项目,我可以上传整个项目。所有单个类都已经过功能测试并按预期执行,它只是通过提供错误的函数在新类中分配值。我在这里附加了容器类和驻留在另一个类中的函数。非常感谢你的帮助!
class masterContainer{
public $mc = array('file','line' => array('line' => array('string','element'=>array())));//this array stores all the contents needed for a file
public function __construct($file){
$this->file = $file;
$this->mc['file'] = $this->file;
$mc['line'] = array();
$mc['line'][$l]['string'] = $line[$l];
$mc['line'][$l]['element'] = array();
$mc['line'][$l]['element'] = $element[$e];
}//end __construct()
}//end masterContainer{}
这是函数
<?php
require_once('/Library/WebServer/Documents/gasDev/super_src/controller/fileController.php');
require_once('/Library/WebServer/Documents/gasDev/super_src/container/masterContainer.php');
require_once('/Library/WebServer/Documents/gasDev/super_src/controller/lineController.php');
require_once('/Library/WebServer/Documents/gasDev/super_src/controller/elementController.php');
class masterControl{
public $fc;//fileHandling
public $container;////masterContainer
public $lc;//lineController
public $ec;//elementController
public function __construct($path){
$this->buildContainer($path);
}//end __construct()
public function buildContainer($path)
{
$this->fc = new fileController($path);//create files
foreach($this->fc->getFiles() as $f){$this->container[] = new masterContainer($f);};//create containers, assign file to memory
// foreach($this->container as $c){echo $c->file."<br>";};//lists all files in container
$i=0;//a counter
foreach($this->container as $c){$this->lc[] = new lineController($c->file);$i++;};//create new lines
//assign lines to memory
$i=0;//a counter
foreach($this->lc as $line){
$j=0;//a counter
//echo $i."<br>";
foreach($line->getLines() as $l){
$this->container[$i]->line[$j] = $l;
//echo $l."<br>";
$j++;
};//assign line to memory
//echo "<br>";
$i++;
};
//make elements
$i=0;
foreach($this->container as $c){
//echo count($c->line)."<br>";
//echo "=-".$i."-=<br>";
$j=0;
foreach($c->line as $l){
//echo $i." - ".$l."<br>";
$this->ec[] = new elementController("*",$l);
foreach($this->ec as $elements){
$k=0;
foreach($elements->getElements() as $e){
//echo $e."<br>";
$this->container[$i]->line[$j]->element[$k] = $e;
//echo $k."<br>";
$k++;
};
};
//echo "__".$j."__<br>";
$j++;
};
$i++;
};
// echo "<br><br>";
// echo "file: ".$this->container[0]->file."<br><br>";
// echo "line: ".$this->container[0]->line[0]."<br>";
// echo "element: ".$this->container[0]->line[0]->element[0]."<br>";
}//end buildContainer()
public function echoArray($array){foreach ($array as $a){echo $a."<br>";};}
public function __toString(){}
}//end mastController{}
$mc = new masterControl('/Library/WebServer/Documents/gasDev/test_files/850_855_csv_tests/850');
?>
答案 0 :(得分:1)
$this->container
未定义,应初始化为数组。
或者:
$this->container[$i]->line[$j]->element[$k]
行或元素未初始化。
调试这样的代码真的很难......