dongma7796 2012-12-13 03:40
浏览 36

无法访问名称中包含句点的PHP对象字段

I've run into an issue with PHP and object key access.

I have a SimpleXMLElement that returns an array of 11 SimpleXMLElements as follows:

SimpleXMLElement Object
(
    [Power.AssetToAssetMapping] => Array
    (
        [0] => SimpleXMLElement Object
            (
                [AssetToAssetMappingID] => 36063
                [Supplier_x0020_Asset_x0020_Type] => Powerstrip
                [..etc..]

When I try to isolate the array using braces, I only see the first record of the array. The other 10 are never output:

print_r( $xml->{'Power.AssetToAssetMapping'} );

When I use the whole object, I see all 11 records:

print_r( $xml );

Is there another way to access the first child of this object? I can foreach over each child of the object returned in $xml and get to each element just fine, but it seems like this is a bug in PHP.

  • 写回答

2条回答 默认 最新

  • dongshuohuan5291 2012-12-13 04:47
    关注

    Just convert SimpleXMLElement Object to Array ;)

    $xml = (array)$xml;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据