foreach正在丢失对象的值

问题描述 投票:0回答:2

所以这是一个完全愚蠢的初学者问题,但是我花了很多时间来调查正在发生的事情,我完全没有更多的想法了。

我正在尝试从CellLineRepository中获取名为“ Cell”的对象的私有值。吸气剂正在工作,它们正在另一个地方使用。

这是我的foreach外观:

$all_cell_lines = CellLineRepository::findAll();
$allcells = [];
foreach ($all_cell_lines as $cell) {
    $allcells[] = [
        "CellID" => $cell->getId(),
        "iPSC-ID" => $cell->getIpscId(),
        "Lab-ID" => $cell->getLabId(),
        "altID" => $cell->getAltId(),
        "project" => $cell->getProject()
    ];
    var_dump($allcells);
}

var_dump()$all_cell_lines看起来不错,但是我丢失了“ iPSC-ID”和“ Lab-ID”。

object(CellLine)#9 (79) {
[
  "id": "CellLine":private
]=>
string(1) "1"
[
  "created_date": "CellLine":private
]=>
string(10) "2019-05-22"
[
  "created_by": "CellLine":private
]=>
string(3) "314"
[
  "last_modified_date": "CellLine":private
]=>
string(10) "2019-11-22"
[
  "last_modified_by": "CellLine":private
]=>
string(3) "301"
[
  "tab_type": "CellLine":private
]=>
string(8) "internal"
[
  "lab_id": "CellLine":private
]=>
string(5) "xxx"
[
  "alt_id": "CellLine":private
]=>
string(7) "xxx"
[
  "provider": "CellLine":private
]=>
string(36) "xxx"

var_dump()的[A $allcells看起来像这样:

    array(1) {
  [
    0
  ]=>
  array(5) {
    [
      "CellID"
    ]=>
    string(1) "1"
    [
      "iPSC-ID"
    ]=>
    string(0) ""
    [
      "Lab-ID"
    ]=>
    string(0) ""
    [
      "altID"
    ]=>
    string(7) "xxx"
    [
      "project"
    ]=>
    string(3) "xxx"
  }
}

有人有线索吗?

php foreach drupal getter
2个回答
0
投票
foreach ($all_cell_lines as $cell) { $allcells[] = [ "CellID" => $cell->id, "iPSC-ID" => $cell->ipsc_id, "Lab-ID" => $cell->lab_id, "altID" => $cell->alt_id, "project" => $cell->project ]; var_dump($allcells);

}

尝试使用您在数据库中的字段名称获取

0
投票
public function getLabId() { return perissionCheck('lab_id') ? $this->lab_id : ''; }

仍然感谢! :)

© www.soinside.com 2019 - 2024. All rights reserved.