Is there any short way to load data to the properties of a class, for each column name matching the properties of the class?

Posted by Ugur Gümüshan on Stack Overflow See other posts from Stack Overflow or by Ugur Gümüshan
Published on 2011-11-16T01:23:36Z Indexed on 2011/11/16 1:50 UTC
Read the original article Hit count: 198

Filed under:
|
|

I want to load data to an instance of an object using its constructor and I write

$this->property=$row["colname"] 

each time for each property.

the mysql_fetch_object function fetches the data as an object but I am not sure if the instance of an object can be assigned to some object from inside. othwerwise I would use

__construct($object) { $this=$object; } //doesn't give any syntax error

Maybe I should look into iteration of properties and use

foreach($object as $key => $value) $value=$object[$key];

or can I assign like

$this=$object;

within the constructor?

© Stack Overflow or respective owner

Related posts about php

Related posts about oop