Jump to content

php overload constructors


dawemu

Recommended Posts

HI all. i'm a beginner to PHP. so i need some help from you to this problem. actually i dont know how to create overload constructors. so please help me to correct this code.

Thanks

 

 

<?php

/*
* Class Name - Search Class
* Author - Damith Mulleriyawa
* Date - 04/11/2008
* Version - 1.0
* Description - Search controller
*/

class Search {

//private attributes for the class
private $studentID;
private $studentFirstName;
private $studentLastName;
private $date;
private $timeIn;
private $timeOut;
private $staffID;
private $staffFirstName;
private $staffLastName;


//defult constructor
public function __construct() {
$num = func_num_args();
$args = func_get_args();
switch($num){
case 0:
$this->__call('__construct0', null);
break;
case 1:
$this->__call('__construct1', $args);
break;
default:
throw new Exception();
}
}

}

//constructor
public function __construct1($studentID,$studentFirstName,$studentLastName, $date, $timeIn, $timeOut) {
$this->studentID = $studentID;
$this->studentFirstName = $studentFirstName;
$this->studentLastName = $studentLastName;
$this->date = $date;
$this->timeIn = $timeIn;
$this->timeOut = $timeOut;

}

public function __construct1($staffID, $staffFirstName, $staffLastName) {
$this->studentID = $studentID;
$this->staffFirstName = $staffFirstName;
$this->staffLastName = $staffLastName;

}

public function getStudentID()
{
return $this->studentID;
}

public function setStudentID($studentID)
{
$this->studentID = $studentID;
}

public function getStudentFirstName()
{
return $this->studentFirstName;
}

public function setStudentFirstName($studentFirstName)
{
$this->studentFirstName = $studentFirstName;
}

public function getStudentLastName()
{
return $this->studentLastName;
}

public function setStudentLastName($studentLastName)
{
$this->studentLastName = $studentLastName;
}


public function getDate()
{
return $this->date;
}

public function setDate($date)
{
$this->date = $date;
}

public function getTimeIn()
{
return $this->timeIn;
}

public function setTimeIn($timeIn)
{
$this->timeIn = $timeIn;
}

public function getTimeOut($timeOut)
{
return $this->null;
}

public function setTimeOut($timeOut)
{
$this->timeOut = $timeOut;
}

public function getStaffID()
{
return $this->staffID;
}

public function setStaffID($staffID)
{
$this->staffID = $staffID;
}

public function getStaffFirstName()
{
return $this->staffFirstName;
}

public function setStaffFirstName($staffFirstName)
{
$this->staffFirstName = $staffFirstName;
}

public function getStaffLastName()
{
return $this->staffLastName;
}

public function setStaffLastName($staffLastName)
{
$this->staffLastName = $staffLastName;
}







}//end of class search


?>

Link to comment
Share on other sites

AFAIK, in PHP 5 and less you can't overload a function in the true OOP sense.  You can provide optional parameters or shove a bunch of configuration parameters into a single array parameter though.

 

Perhaps you can in PHP6 but I'm uninformed about that.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.