一整天都在把我的头从桌子上敲下来。
// Iterate over project array to populate release data
for ($i = 0; $i < count($data); $i++) {
$data[$i]->setProjectReleaseSchedule( $proj_scheds[$i] );
//Get each projects Est and Act hours
$options = new stdClass;
$options->default = true;
$options->project_id = $data[$i]->getProjectId();
$options->department_id = $person_dm->getPersonDepartmentId();
//works; AKA: property get assigned an int thatr incriments evern loop
//$data[$i]->data->proj_hours = $this->counter++;
//$weekly_report_dm->getProjectHours returns an object w/ populated properties
$data[$i]->data->proj_hours = $weekly_report_dm->getProjectHours($options);
//As a test, this dumps what is expected...
echo'<pre>';
print_r( $data[$i]->data->proj_hours );
echo'</pre>';
}
echo'<pre>';
//After the loop completes and I try to dump the data the property $data->data->proj_hours is assigned an object..
//but the object properties are all null :(.
print_r( $data );
echo'</pre>';
exit;
正如你所看到的,我在一个对象数组上循环;对于每个对象,我都有另一种数据方法,它返回预期的数据。“print_r($data[$i]->data->proj_hours);”。但是,一旦循环完成并且我尝试转储该对象分配给父对象的数据,但所述对象的属性为空/空白。
所以问题是:为什么我可以将 INT、STRINGS 等分配给对象属性,并且它们会在 foreach 循环之外持续存在。但是当一个对象属性分配给一个foreach循环内的父对象时,这些值不会持续存在吗?