<?php Load Class//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 ();
Automatically load class//1. All class filenames and class names should be consistent//2. All class files are placed under the same file//3. All class file naming rules are consistent with function __autoload ($cname) { require_once ("./$ Cname.class.php "); } $t = new test (); $t->ceshi (). ' <br> '; $s = new Ren (); $s->test ();
Two methods of magic
class ren{public $name; Public function say () {echo "Output object method"; }//The method of the output object public function __tostring () {echo "another output method"; echo $s->__tostring (); Return "another output method";//echo $s; }//method for cloning an object public function __clone () {$this->name = "Riven";//$this represents a clone (cloned object)}} $s = new Ren ();//ech O $s->__tostring ();//output string//$s->say (); $s->name = "small V"; var_dump ($s); $s 1 = clone $s; Var_dump ($s 1);?