Take the 2-minute tour ×

I have mysql table with collumns like 'operation.date', 'operation.name' and etc. After fetching that table data as object with $mysqli->fetch_object() i get this (print_r of row):

stdClass Object
[id] => 2
[operation.date] => 2010-12-15
[operation.name] => some_name

how do I acces operation.date and operation.name and all other weirdly named object properties?

share|improve this question
This is a duplicate. The answer is, it's not a valid property. You should change it. But you can use $obj->{'operation.date'} to access it. –  Gordon Mar 18 '11 at 11:07
possible duplicate of Hyphens in Keys of Object and also How do I access this object property –  Gordon Mar 18 '11 at 11:14
Sorry for that. Was searching but not for hyphens. –  egis Mar 18 '11 at 11:25
No problem. Wasnt that easy to find anyway. –  Gordon Mar 18 '11 at 11:26

3 Answers 3

up vote 13 down vote accepted

Specify aliases in your SQL query like SELECT column AS nameWithoutDots ...
or access these properties with $object->{'operation.name'}
or cast the object to array like this: $obj = (array)$obj; echo $obj['operation.name'].

share|improve this answer
+1 for telling the OP how to cure the cause and not the symptoms –  Gordon Mar 18 '11 at 11:15
I know about aliases, but too much effort to write miles long query with all the columns as aliases :) Since your answer was most informative I will accept it ;) Thanks for all the answers. –  egis Mar 18 '11 at 11:24

To access these attributes you need to wrap them with curly brackets:

echo $object->{operation.date} //2010-12-15

If you set an attribute this way the offending symbol gets removed, allowing you to access the attribute as echo $object->operationdate //2010-12-15

share|improve this answer
+1 but operation.date needs to be wrapped in quotes I think. –  Pekka 웃 Mar 18 '11 at 11:11

Change the sql to return valid property names using the 'as' feature

eg. select operation.date as date

share|improve this answer

Your Answer


