本文整理汇总了PHP中test::overlodedFunction方法的典型用法代码示例。如果您正苦于以下问题:PHP test::overlodedFunction方法的具体用法?PHP test::overlodedFunction怎么用?PHP test::overlodedFunction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类test
的用法示例。
在下文中一共展示了test::overlodedFunction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
class test
{
public function __construct()
{
//Your logic for constructor
}
public function __call($method_name, $parameter)
{
if ($method_name == "overlodedFunction") {
$count = count($parameter);
switch ($count) {
case "1":
//Business log in case of overlodedFunction function has 1 argument
echo "You are passing 1 argument";
break;
case "2":
//Incase of 2 parameter
echo "You are passing 2 parameter";
break;
default:
throw new exception("Bad argument");
}
} else {
throw new exception("Function {$method_name} does not exists ");
}
}
}
$a = new test();
$a->overlodedFunction("ankur");
$a->overlodedFunction("techflirt", "ankur");
示例2: exception
// //Business log in case of overlodedFunction function has 1 argument
// echo "You are passing 1 argument";
// break;
// case "2": //Incase of 2 parameter
// echo "You are passing 2 parameter";
// break;
// default:
// throw new exception("Bad argument");
// }
} else {
throw new exception("Function {$method_name} does not exists ");
}
}
}
$a = new test();
$a->overlodedFunction(1);
$a->overlodedFunction(1, 2, 3, 4);
echo "<br/>";
/**
* Method : Function Overriding.
*/
class ParentOne
{
function Foo()
{
return "Calling from Parent Foo";
}
}
class ChildOne extends ParentOne
{
function Foo()