汽车南站时刻表,幕堂春,青岛旅游网
实例如下所示:
<?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); ?>
以上这篇基于php的加载类操作以及其他两种魔术方法的应用实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
YII2框架中使用RBAC对模块,控制器,方法的权限控制及规则的使用示例
YII2框架中ActiveDataProvider与GridView的配合使用操作示例
PhpStorm的使用教程(本地运行PHP+远程开发+快捷键)
网友评论