一起源码网

  • www.171739.xyz
  • 全球最大的互联网技术和资源下载平台
搜索
猜你喜欢
查看: 8218|回复: 1
打印 上一主题 下一主题

关于PHP的加载类操作及其他魔术方法的应用

[复制链接]

0

主题

0

帖子

1万

积分

钻石会员

Rank: 8Rank: 8

积分
17424
QQ
跳转到指定楼层
楼主
发表于 2020-4-22 04:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
<?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);
?>

分享到:  QQ好友和群QQ好友和群
收藏收藏
回复

使用道具 举报

0

主题

20

帖子

64

积分

注册会员

Rank: 2

积分
64
沙发
发表于 2022-9-27 19:48 来自手机 | 只看该作者
html静态网页源代码
回复

使用道具 举报

一起源码让程序更轻更快

www.171739.xyz

工作时间 周一至周六 8:00-17:30

侵权处理

客服QQ点击咨询

关注抖音号

定期抽VIP

Copyright © 2016-2021 https://www.171739.xyz/ 滇ICP备13200218号

快速回复 返回顶部 返回列表