You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.1 KiB
59 lines
1.1 KiB
<?php
|
|
|
|
use a\cls_a;
|
|
|
|
class add{
|
|
public function getVal($n,$m){
|
|
return $n + $m;
|
|
}
|
|
}
|
|
|
|
class sub
|
|
{
|
|
public function getVal($n,$m)
|
|
{
|
|
return $n-$m;
|
|
}
|
|
}
|
|
|
|
class mul
|
|
{
|
|
public function getVal($n,$m)
|
|
{
|
|
return $n * $m;
|
|
}
|
|
}
|
|
|
|
class div
|
|
{
|
|
public function getVal($n,$m)
|
|
{
|
|
return $n / $m;
|
|
}
|
|
}
|
|
|
|
//工程类:用来创建对象
|
|
class mathOpt{
|
|
public static function createObj($opt){
|
|
switch ($opt)
|
|
{
|
|
case '+':
|
|
return new add();
|
|
break;
|
|
case '-':
|
|
return new sub();
|
|
break;
|
|
case '*':
|
|
return new mul();
|
|
break;
|
|
case '/':
|
|
return new div();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
$obj = mathOpt::createObj('*');
|
|
$ret=$obj -> getVal(5,7);
|
|
echo $ret;
|
|
?>
|