Monday, 14 August 2017

oop - php object attribute with dot in name



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?


Answer



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'].


No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...