Accessing Class Properties with Spaces

PhpOopClassCodeigniterProperties

Php Problem Overview


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] ?

Php Solutions


Solution 1 - Php

You can do it this way:

$object->{'Date Found'}

Solution 2 - Php

have you tried

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

Or simply

$object->{'Date Found'};

Solution 3 - Php

try

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

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKemal FadillahView Question on Stackoverflow
Solution 1 - PhpImi BorbasView Answer on Stackoverflow
Solution 2 - PhpNemanjaView Answer on Stackoverflow
Solution 3 - PhpCatalinView Answer on Stackoverflow