如果我有一个包含以%符号开头的属性的对象,我该如何获取其值.
如果我使用
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)
我知道我不应该在变量名中使用%,但这不是我的行为而且我坚持使用它.
我有以下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) 我有一个对象,它有一个名为“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)
我只是有这个属性的问题,中间有“-”;我怎么解决这个问题?
谢谢