Accessing Class Properties with Spaces

前端 未结 3 1198
北恋
北恋 2020-11-29 05:49

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

So I can access [Sector] by using $object->S

相关标签:
3条回答
  • 2020-11-29 06:13

    have you tried

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

    Or simply

    $object->{'Date Found'};
    
    0 讨论(0)
  • 2020-11-29 06:29

    try

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

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

    0 讨论(0)
  • 2020-11-29 06:30

    You can do it this way:

    $object->{'Date Found'}
    
    0 讨论(0)
提交回复
热议问题