时间:2021-07-01 10:21:17 帮助过:14人阅读
class MyClass
{
funciton a(){
echo 'a';
}
}
class MyClassExted extends MyClass
{
function b(){
echo 'b';
}
}
$test = new MyClassExted();
$test->b();
$test = new MyClass();
$test->b();
class MyClass
{
funciton a(){
echo 'a';
}
}
class MyClass extends MyClass
{
function b(){
echo 'b';
}
}
$test = new MyClass();
$test->b();
class MyClass
{
function a(){
echo 'a';
}
function b(){
echo 'MyClass b';
}
}
class MyClassExtend extends MyClass
{
function b(){
echo 'MyClassExtend b';
}
}
$MyClass = new MyClass();
$MyClass->b();//MyClass b
$MyClassExtend = new MyClassExtend();
$MyClassExtend->b();//MyClassExtend b
class MyClass
{
funciton a(){
echo 'a';
}
function __call($name, $param) {
if(function_exists($name)) {
return call_user_func_array($name, $param);
}
}
}
function b() {
echo $b;
}
$test = new MyClass();
$test->b();
class MyClass
{
function a(){
echo 'a';
}
function __call($name, $param){
if($name=='b'){
echo 'b';
}
}
}
$obj = new MyClass();
$obj->b();
class api_base
{
function a(){
echo 'a111';
}
function __call($name, $param) {
static $methods = array();
if(!method_exists($this, $name)){
list($api, $fun) = explode('_',$name);
empty($fun) && $fun = 'index';
if(!isset($methods[$api])){
include_once('class.api.'.$api.'.php');
$method = 'api_'.$api;
$methods[$api] = new $api();
}
if(!method_exists($methods[$api], $fun)){
die('error');
}
call_user_func_array(array($methods[$api], $fun), $param);
}
}
}
$test = new api_base();
$test->b(1,2,3);
$test->b(4,5,6);
$test->b_test(1,2,3);
$test->b_haha(4,5,6);
?>
class.api.b.php:
class api_b extends api_base
{
function index($a,$b,$c){
echo "$a - $b - $c
";
}
function test($a,$b,$c){
echo "$a - $b - $c
";
}
function haha($a,$b,$c){
echo "$a - $b - $c
";
}
}
?>