PHP结肠属性名 [英] PHP colon in property name

查看:87
本文介绍了PHP结肠属性名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有被设定为一个变量$条目:

I have a variable $entry which is set to:

stdClass的对象(
      [IM:名字] => stdClass的对象
          (
              [标签] =>惊人的断路器
          )
  等等。

stdClass Object ( [im:name] => stdClass Object ( [label] => Amazing Breaker ) etc.

如何访问值神奇断路器?

How can I access the value "Amazing Breaker"?

我试图定义一个常量:

define("IMNAME", 'im:name');

但使用:

foreach ($json_output->feed->entry as $entry) {
if (isset($entry->IMNAME->label))

返回FALSE。

returns FALSE.

问题似乎是结肠。对于没有冒号键code将返回TRUE。

Problem seems to be the colon. For a key without colon the code would return TRUE.

推荐答案

您可以使用免费的形式语法与特殊属性名花括号:

You can use the free-form syntax with curly braces for 'special' property names:

if (isset($entry->{'im:name'}->label))

这篇关于PHP结肠属性名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆