我無法理解代碼的工作?我不知道爲什麼?它甚至有可能嗎?方法重載和類繼承
我總是想調用一個默認的類和方法。但實際上取決於參數givven。我想從該特定客戶加載方法?
<?php
#System Defaults
namespace DefaultNameSpace;
class defaultClass{
private $property;
public function __construct($cusotmer)
{
if (isset($cusotmer)){
$namespace = '\Customer' . $cusotmer .'Namespace\defaultClass';
# create new dynamic object
return new $namespace();
} else {
return $this;
}
}
public function printInvoice(){
echo 'Default Print';
}
public function createInvoice($invoice){}
}
#Customer One defaults
namespace CustomerOneNamespace;
class defaultClass extends \DefaultNameSpace\defaultClass {
private $property;
public function __construct()
{
return $this;
}
public function printInvoice(){
echo 'Customer One';
}
public function createInvoice ($invoice){
echo 'Create invoice Customer One '.$invoice;
}
}
# Customer Two Defaults
namespace CustomerTwoNamespace;
class defaultClass extends \DefaultNameSpace\defaultClass {
private $property;
public function __construct()
{
return $this;
}
public function printInvoice(){
echo 'Customer Two';
}
}
# Call alsways default Class
$test = new \DefaultNameSpace\defaultClass('Two');
$test->printInvoice();
$test->createInvoice('123456');
?>
構造函數不能返回任何東西。 –