Forum Moderators: coopster
I hope to make class like
class student
{
public funcion student($student_id)
{
if(student not in data base)
{
return false or something similar
}
}
}
then use it like this
if (!$student = new student($$student_id))
{
do what ever happens when there's an error
}
if (mysql_num_rows($query)==0)
{
return false;
}
else
{
return $whatever;
}
}
}
Then when you create the class do:
$student = new student();
if (!$student->student($id))
{
//no student exists
}
else
{
//hello there
}
class student extends user
{
public funcion __constructor($student_id)
{
Set $this-> vars needed to distinguish the "student" class from other classes, that also extend the "user" class
parent :: __construct($student);
}
}
// The parent constructor mentod does the following
class user
{
public funcion __constructor($user_id)
{
if (mysql_num_rows($query)==0)
{
return false or something similar
}
else
{
set a whole bunch of $this-> vars with query result
}
}
}
then use
if (!$student = new student($student_id))
{
// Student does not exist
}
$student = new Student($id);
if (!$student->id)
{
echo "Sorry, that person is in our DB";
}
otherwise
$person = new Person($id);
if (!$person->isStudent())
{
echo "Sorry, Jethro Bodine is not a student";
}
It's impossible to return a value from a constructor. What you might want to do is utilize PEAR and if an error occurs in your constructor, constuct an error object. Then in your code, test the object with the:
if (PEAR::isError($object)) {
// do something, or don't
}
Of if you don't feel like using pear, just use the PHP is_a() [us3.php.net] function to test the object after it's created.