php类的重载函数简单的实现
来源:互联网 发布:浙江软件考试报名 编辑:程序博客网 时间:2024/06/08 02:49
<?php/* * 这样写出来的基类下次就可以直接修改很方便了 * */class basic_inter{ private $count; private $value; private $result; function __construct() { $this->count=0; } function setValue($cout,$arrs) { $this->count=$cout; $this->value=$arrs; } private function ChooseFun() { switch ($this->count){ case 1: return $this-> GetMax_with_One_Parament($this->value[0]); break; case 2: return $this-> GetMax_with_Two_Parament($this->value[0],$this->value[1]); break; case 3: return $this->GetMax_with_Three_Parament($this->value[0],$this->value[1],$this->value[2]); break;
//这里你需要什么函数就可以自己去添加 default: return -99999999999; break; } } private function adjuage($min,$max) { return $max>$min?$max:$min; } private function GetMax_with_One_Parament($value) { return $value; } private function GetMax_with_Two_Parament($value1,$value2) { return $this->adjuage($value1,$value2); } private function GetMax_with_Three_Parament($value1,$value2,$value3) { return $this->adjuage($this->adjuage($value1,$value2),$value3); } function getValues() { $this->result=$this->ChooseFun(); return $this->result; }}class Compare extends basic_inter{ private $para; private $arr_value; private $result; function __construct() { $this->para=0; } function GetMax() { $this->arr_value=func_get_args(); $this->para=func_num_args(); //获取到了其中的数组的值 $this->coordinate_function(); } private function coordinate_function() { $this->setValue($this->para,$this->arr_value); $this->result=$this->getValues(); echo $this->result; }}$c = new Compare(); //实例化"计算"类echo "两个数比较示例:";echo $c->GetMax(12,-26)."<br>"; //调用成员方法,获得输入的数的较大值,输出12echo "三个数比较示例:";echo $c->GetMax(12,25,31)."<br>"; //调用成员方法,获得输入的数的较大值,输出31?>其实这个是非常简单的,php本身不支持重载的,同时还有简单的方法就是用缺省函数的方法去解决它。
阅读全文
0 0
- php类的重载函数简单的实现
- PHP:函数的重载
- PHP 构造函数的重载
- 函数重载的简单示例
- 函数重载的简单介绍
- PHP实现函数重载
- matrix 重载操作,firend 函数实现 简单的例子
- 【C++】编写一个简单的函数实现重载。
- 函数重载的实现机制
- JavaScript的重载函数实现
- 函数重载的实现原理
- c函数重载的实现
- php关于重载函数的笔记
- 重载父类虚函数的简单方法
- 简单的函数重载和模板
- PHP中实现重载的方法
- C++ 简单类中实现各种操作符的重载
- 使用 PHP中的str_replace函数和preg_replace函数 实现一个简单的 静态数据生成类
- codeforces 887A. Div. 64
- 一道 google曾出过的笔试题:编程实现对数学一元多项式的相加和相乘操作
- Android 反编译机制
- Week16 总结
- 表达式计算器-iExpr
- php类的重载函数简单的实现
- SSL/TLS
- qt5 ubuntu 14.04安装与配置
- bzoj 5094: 硬盘检测(概率)
- Logistic回归计算过程的推倒
- HPU 1151(思维)
- Verilog中assign的使用
- 多样沉浸式要点总结(看了必有收获)
- 字符串翻转操作