《關(guān)于PHP的加載類操作以及其他兩種魔術(shù)方法應(yīng)用》要點(diǎn):
本文介紹了關(guān)于PHP的加載類操作以及其他兩種魔術(shù)方法應(yīng)用,希望對您有用。如果有疑問,可以聯(lián)系我們。
<?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();
主動(dòng)加載類
//1.所有類文件名和類名要堅(jiān)持一致
//2.所有類文件放在統(tǒng)一文件下
//3.所有類文件定名規(guī)則一致
function __autoload($cname){
require_once("./$cname.class.php");
}
$t = new test();
$t->ceshi().'<br>';
$s = new Ren();
$s->test();
兩種魔術(shù)辦法
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代表復(fù)本(克隆的工具)
}
}
$s = new Ren();
//echo $s->__tostring();//輸入字符串
//$s->say();
$s->name = "小V";
var_dump($s);
$s1 = clone $s;
var_dump($s1);
必修>
歡迎參與《關(guān)于PHP的加載類操作以及其他兩種魔術(shù)方法應(yīng)用》討論,分享您的想法,維易PHP學(xué)院為您提供專業(yè)教程。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/12407.html