嗨,我的代码非常简单,我试图使用面向对象的方法作为学习练习,但是识别类和实现有点令人困惑
因此,在我当前的程序中,我有一个函数,我正在计算用户在一个月内某些任务需要多少时间以及剩余多少时间:
例如 function timeremaining ($dob, $task1start=null, $task1end=null, $item2start=null, $task2end=null)
如果我试图在面向对象编程中做类似的事情,我想我会使用这样的东西,但不确定:
class person extends task {
public $age;
public $name;
public $phoneno ;
public $totaltimethismonth;
}
class task extends time{
public $name ;
public $timefrom;
public $timeto;
public function getDuration($name,$timefrom,$timeto)
{
list($hours, $minutes) = explode(':', $timefrom);
$startTimestamp = mktime($hours, $minutes);
list($hours, $minutes) = explode(':', $timeto);
$endTimestamp = mktime($hours, $minutes);
$seconds = $endTimestamp - $startTimestamp;
$totaldurationinseconds=$totalsecondsinday - $seconds;
return $totaldurationinseconds;
}
}
class time {
public $hours ;
public $minutes;
public $seconds;
//not sure if time should be used?
}
$newperson = new person;
$duration=$newperson->getDuration("gardening","10:00","17:00");
$totaltime=$newperson->totaltimethismonth;
echo "remaing time this month is $totaltime-$duration;
任何帮助都感激不尽