Casting

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xLechugasx
Forum Newbie
Posts: 14
Joined: Wed Aug 28, 2002 9:56 am

Casting

Post 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
User avatar
nathus
Forum Commoner
Posts: 49
Joined: Thu Dec 12, 2002 6:23 pm

Post 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
Post Reply