`
isiqi
  • 浏览: 16052917 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

php5中的overloading

PHP 
阅读更多
php5中的overloading始终没有什么惊喜,实现起来居然十分曲折的,这点还是比不上java哦
,其中是通过_call来实现的,这个方法用来监视一个对象中的其它方法。如果你试着调用一个对象中不存在的方法,__call 方法将会被自动调用。
比如

<?php
class Magic {
function __call($name,$arguments) {
if($name=='foo') {
if(is_int($arguments[0])) $this->foo_for_int($arguments[0]);
if(is_string($arguments[0])) $this->foo_for_string($arguments[0]);
}
} private function foo_for_int($x) {
print("oh an int!");
} private function foo_for_string($x) {
print("oh a string!");
}
} $x = new Magic();
$x->foo(3);
$x->foo("3");
?>

你看多不好呀,还要手工去判断参数的类型

分享到:
评论

相关推荐

    PHP5 完整官方 中文教程

    PHP5 完整官方 中文教程 版权信息 前言 入门指引 简介 简明教程 安装与配置 安装前需要考虑的事项 Unix 系统下的安装 Mac OS X 系统下的安装 Windows 系统下的安装 PECL 扩展库安装 还有问题? 运行时配置 语言参考 ...

    PHP5中文参考手册

    Object overloading — Object property and method call overloading OCI8 — Oracle 函数 ODBC — ODBC Functions (Unified) ODBC and DB2 (PDO) — ODBC and DB2 Functions (PDO_ODBC) OGG/Vorbis — oggvorbis ...

    php帮助文档,php。chm,php必备的中文手册

    Object property and method call overloading XCVI. Oracle 函数 XCVII. ODBC Functions (Unified) XCVIII. ODBC and DB2 functions (PDO_ODBC) XCIX. oggvorbis C. OpenAL Audio Bindings CI. OpenSSL Functions ...

    PHP5 开发手册 简体中文手册

    Object property and method call overloading XCV. Oracle 函数 XCVI. ODBC Functions (Unified) XCVII. ODBC and DB2 functions (PDO_ODBC) XCVIII. oggvorbis XCIX. OpenAL Audio Bindings C. OpenSSL Functions...

    php中文完全开发手册

    Object property and method call overloading LXXX. PDF functions LXXXI. Verisign Payflow Pro Functions LXXXII. PHP Options&Information LXXXIII. POSIX Functions LXXXIV. PostgreSQL 数据库函数库 LXXXV. ...

    PHP面向对象程序设计重载(overloading)操作详解

    本文实例讲述了PHP面向对象程序设计重载(overloading)操作。分享给大家供大家参考,具体如下: 重载 PHP中的”重载”与其它绝大多数面向对象语言不同,只是他们都是用的相同的名词而已。传统的”重载”是用于提供...

    php手册PHP5研究室编无乱码版本chm

    Object property and method call overloading XCIII. ODBC and DB2 functions (PDO_ODBC) XCIV. ODBC Functions (Unified) XCV. oggvorbis XCVI. OpenAL Audio Bindings XCVII. OpenSSL Functions XCVIII. ...

    php手册.chm,php手册

    Object property and method call overloading XCIII. ODBC and DB2 functions (PDO_ODBC) XCIV. ODBC Functions (Unified) XCV. oggvorbis XCVI. OpenAL Audio Bindings XCVII. OpenSSL Functions XCVIII. Oracle ...

    PHP函数参考手册大全

    Object property and method call overloading XCIII. ODBC and DB2 functions (PDO_ODBC) XCIV. ODBC Functions (Unified) XCV. oggvorbis XCVI. OpenAL Audio Bindings XCVII. OpenSSL Functions XCVIII. Oracle ...

    PHP手册2007整合中文版

    PHP,即“PHP: Hypertext Preprocessor”,是一种被广泛使用的开放源代码多用途脚本语言,尤其适用于 web 开发并可以嵌入到 HTML 中去。其语法利用了 C,Java 和 Perl,非常容易学习。该语言的主要目标是让 web 开发...

    中文版PHP使用手册

    Object property and method call overloading XCIII. ODBC and DB2 functions (PDO_ODBC) XCIV. ODBC Functions (Unified) XCV. oggvorbis XCVI. OpenAL Audio Bindings XCVII. OpenSSL Functions XCVIII. Oracle ...

    PHP官方手册中文版

    Object property and method call overloading CVII. Oracle 函数 CVIII. ODBC Functions (Unified) CIX. ODBC and DB2 Functions (PDO_ODBC) CX. oggvorbis CXI. OpenAL Audio Bindings CXII. OpenSSL ...

    PHP 魔术方法整理

    魔术方法:魔术函数是PHP中内置的语言特性,当程序执行到某种情况时,如果定义了这些魔术函数 (php手册中称之为“Overloading”),则PHP会调用他们,同时也会传入相应的参数,可以认为是PHP执行过程中的钩子函数

    经典收藏最全php5.0查询手册

    Object property and method call overloading XCIII. ODBC and DB2 functions (PDO_ODBC) XCIV. ODBC Functions (Unified) XCV. oggvorbis XCVI. OpenAL Audio Bindings XCVII. OpenSSL Functions XCVIII. Oracle ...

    PHP手册(带评论版-2008-03-14).part2.rar

    Object property and method call overloading XCIII. ODBC and DB2 functions (PDO_ODBC) XCIV. ODBC Functions (Unified) XCV. oggvorbis XCVI. OpenAL Audio Bindings XCVII. OpenSSL Functions XCVIII. Oracle ...

    PHP手册(带评论版-2008-03-14).part1.rar

    Object property and method call overloading XCIII. ODBC and DB2 functions (PDO_ODBC) XCIV. ODBC Functions (Unified) XCV. oggvorbis XCVI. OpenAL Audio Bindings XCVII. OpenSSL Functions XCVIII. Oracle ...

    PHP面相对象中的重载与重写

    重写Overriding是父类与子类之间多态性的一种表现,重载Overloading是一个类中多态性的一种表现。Overloaded的方法是可以改变返回值的类型。也就是说,重载的返回值类型可以相同也可以不同。 重载(Overloading) a、...

    PHP中的魔术方法总结和使用实例

    它们在特定的情况下被触发,都是以双下划线开头,你可以把它们理解为钩子,利用模式方法可以轻松实现PHP面向对象中重载(Overloading即动态创建类属性和方法)。魔术方法很多还是成对出现的,以下列出目前PHP中所有...

    PHP函数常用用法小结

    魔术函数是PHP中内置的语言特性,当程序执行到某种情况时,如果定义了这些魔术函数(php手册中称之为“Overloading”),则PHP会调用他们,同时也会传入相应的参数,可以认为是PHP执行过程中的钩子函数。常见的魔术...

Global site tag (gtag.js) - Google Analytics