关于PHP的加载类操作以及其他两种魔术方法应用
<?php
加载类
//include("./Ren.class.php");
//include "./Ren.class.php";
include_once("./Ren.class.php");
include_once("./Ren.class.php");
$f = new Ren();
$f->test();
require("./Ren.class.php");
require_once("./Ren.class.php");
require_once "./Ren.class.php";
$f = new Ren();
$f->test();
自动加载类
//1.所有类文件名和类名要保持一致
//2.所有类文件放在同一文件下
//3.所有类文件命名规则一致
function __autoload($cname){
require_once("./$cname.class.php");
}
$t = new test();
$t->ceshi().'<br>';
$s = new Ren();
$s->test();
两种魔术方法
class Ren{
public $name;
public function say(){
echo "输出对象方法";
}
//输出对象的方法
public function __tostring(){
echo "另一种输出方法"; //echo $s->__tostring();
return "另一种输出方法";//echo $s;
}
//克隆对象的方法
public function __clone(){
$this->name = "Riven";//$this代表复本(克隆的对象)
}
}
$s = new Ren();
//echo $s->__tostring();//输出字符串
//$s->say();
$s->name = "小V";
var_dump($s);
$s1 = clone $s;
var_dump($s1);
?>
最新文章
- fopen函数和fread函数、fwrite函数
- C# Async, Await and using statements
- spring IOC装配Bean(注解方式)
- axis 理解
- 快手4.0 (KSCAD)
- BZOJ2159 : Crash 的文明世界
- 最近发现docker感觉不错
- 选择Nodejs的N个理由
- Restful风格的简单实现办法
- 本地代码git到github上
- js 实现 input type=";file"; 文件上传示例代码
- 编程从入门到提高,然后放弃再跑路(Java)
- bzoj 2510 弱题 矩阵乘
- Linux网络技术管理及进程管理(week2_day4)--技术流ken
- zabbix监控nginx连接数量
- ORACLE 计算时间相减间隔
- http://www.bugku.com:Bugku——变量1(http://120.24.86.145:8004/index1.php)
- php+C#.net混合开发
- ul li剧中对齐
- Json.Net 反序列化成匿名对象