Page 1 of 1

Casting

Posted: Wed Dec 18, 2002 6:45 pm
by xLechugasx
Hi to all!
I read a record from a mySql table with mysql_fetch_object.
Is there a way to cast it to a particular class, for example, Student? Of course, I have defined a Student class.
Can I do it?
Thanks a lot,
Nicolas

Posted: Wed Dec 18, 2002 7:36 pm
by nathus
not sure if you can cast from one class to another. however you could possibly create a constructor that accepts an object and copy the field values like so.

Code: Select all

class Student {
  var $name;
  var $grade;
 

  function Student($obj) {
  $this->name = $obj->name;
  $this->grade = $obj->grade;
  }
}
or something similar