相关疑难解决方法(0)

对象属性名中的特殊字符

如果我有一个包含以%符号开头的属性的对象,我该如何获取其值.

如果我使用

echo $myobject->%myproperty;
Run Code Online (Sandbox Code Playgroud)

我收到一个错误

Parse error: syntax error, unexpected '%', expecting T_STRING or T_VARIABLE
Run Code Online (Sandbox Code Playgroud)

我知道我不应该在变量名中使用%,但这不是我的行为而且我坚持使用它.

php syntax

25
推荐指数
1
解决办法
1万
查看次数

PHP JSON解码:带有'$'问题的数组

我有以下JSON文件作为输入,

{
  "$type": "NanoWebInterpreter.WebInputData, NanoWebInterpreter",
  "NBBList": {
    "$type": "System.Collections.Generic.List`1[[monoTNP.Common.NBB, monoTNP.Common]], mscorlib",
    "$values": [
      {
        "$type": "monoTNP.Common.NBB, monoTNP.Common",
        "ID": "id-0065-00000003",
        "MPList": {
          "$type": "System.Collections.Generic.List`1[[monoTNP.Common.MP, monoTNP.Common]], mscorlib",
          "$values": [
            {
              "$type": "monoTNP.Common.EllipticalMP, monoTNP.Common",
              "Eccentricity": 1.0,
              "ID": "id-0065-00000006",
              "ParticleIndex": -1,
              "DispersionInteractionStrength": 0.0,
              "DispersionInteractionRange": 2.5,
              "CharacteristicSize": 0.0,
              "CenterOfMass": "<0,0,0>",
              "OrientationVector": "<>"
            },
            {
              "$type": "monoTNP.Common.CubeMP, monoTNP.Common",
              "ID": "id-0065-00000005",
              "ParticleIndex": -1,
              "DispersionInteractionStrength": 0.0,
              "DispersionInteractionRange": 2.5,
              "CharacteristicSize": 0.0,
              "CenterOfMass": "<0,0,0>",
              "OrientationVector": "<>"
            },
            {
              "$type": "monoTNP.Common.CircularMP, monoTNP.Common",
              "ID": "id-0065-00000004",
              "ParticleIndex": -1,
              "DispersionInteractionStrength": 0.0,
              "DispersionInteractionRange": 2.5,
              "CharacteristicSize": …
Run Code Online (Sandbox Code Playgroud)

php json

6
推荐指数
1
解决办法
627
查看次数

如何获取名称之间有破折号 (-) 的对象的属性

我有一个对象,它有一个名为“Employee-ID”的属性;

我试图通过以下方式获得其价值:

echo ($row->Employee-ID);
Run Code Online (Sandbox Code Playgroud)

但是 PHP 一直在说:

Undefined property: stdClass::$Employee
 Use of undefined constant ID - assumed 'ID' 
Run Code Online (Sandbox Code Playgroud)

我只是有这个属性的问题,中间有“-”;我怎么解决这个问题?

谢谢

php

0
推荐指数
1
解决办法
323
查看次数

标签 统计

php ×3

json ×1

syntax ×1