我在从我的 Deliveries 访问 Jobinfo 类时遇到问题。问题是我需要能够从我的子类中获取 getQty 的值,并且我还需要能够使用父类的属性获取 qty_ship 方法。我怎样才能做到这一点?它似乎不起作用并且对此感到非常困惑......我希望能够动态地使用来自 Parent->Child 和 Child->Parent 的方法。
class jobInfo
{
public $JOB_ID;
private $deliveries; // DELIVERIES CLASS
function __construct($job_id)
{
$this->JOB_ID=$job_id;
$this->deliveries = new Deliveries();
}
public function getQty()
{
return $this->query_s('job_sheet','*', 'job_id',$this->JOB_ID, 1, 'qty');
//returns a quantity from query method
}
}
class Deliveries extends jobInfo
{
function __construct(){}
public function qty_ship()
{
$qty = 0;
$SQL = mysql_query("SELECT * FROM deliveries WHERE jID='".parent::JOB_ID."'") or die(mysql_error());
$rows = mysql_num_rows($SQL);
if($rows>0)
{
while($data = mysql_fetch_array($SQL))
{
$qty += $data['qty_shipped'];
}
}
return $qty;
}
public function getTotalBO()
{
$qty = parent::getQty();
$totalship = $this->qty_ship();
$x = $qty-$totalship;
return $x;
}
}
$A = new Jobinfo(15);