【发布时间】:2014-06-05 11:48:19
【问题描述】:
我突然卡在这里:
$source = (object) array(
'field_phone' => array(
'und' => array(
'0' => array(
'value' => '000-555-55-55',
),
),
),
);
dsm($source);
$source_field = "field_phone['und'][0]['value']";
dsm($source->{$source_field}); //This notation doesn't work
dsm($source->field_phone['und'][0]['value']); //This does
-
dsm()是 Drupal 开发人员函数,用于调试打印变量、对象和数组。
为什么$source 对象不理解$obj->{$variable} 表示法?
注意:未定义的属性:stdClass::$field_phone['und']['0']['value']
【问题讨论】:
-
$source->{$source_field}正在搜索 $source 的 direct 属性...。嵌套数组不是直接属性,只有顶层是直接属性... .$source_field = "field_phone"; dsm($source->{$source_field}['und'][0]['value']); -
请注意,根据它自己的文档,dsm() 是一个“名称不佳的遗留函数”,您应该使用 dpm() 代替。
标签: php object drupal properties notation