Accessing Class Properties with Spaces

二次信任 提交于 2020-01-09 02:14:29

问题


stdClass Object ([Sector] => Manufacturing [Date Found] => 2010-05-03 08:15:19)

So I can access [Sector] by using $object->Sector but how can I access [Date Found] ?


回答1:


You can do it this way:

$object->{'Date Found'}



回答2:


have you tried

$property = 'Date Found';
$object->{$property};

Or simply

$object->{'Date Found'};



回答3:


try

$var="Date Found"; $this->$var

But I doubt that much you can have spaces in class properties names in php




回答4:


Replace the spaces with underscores in the property name with property name in all lower case:

if $property = 'Date Found';
    use $property = 'date_found';
    $object->{$property};


来源:https://stackoverflow.com/questions/7027615/accessing-class-properties-with-spaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!