一:autoload函式
i : 為了例項化php中的類物件,需要通過一定的方法尋找到類的定義。
通常情況下,類會定義在一個單獨的檔案中。
現在我們建立一個資料夾libs,建立檔案 test.php和test.class.php
libs/test.php 和 libs/test.class.php 和 index.php
1:libs/test.php 的**
12:libs/test.class.php 的**<?php
2class
test
6 }
13:index.php 的**<?php
2class
test
6 }
1ii:其他方法<?php2 //
設定autoload的裝載擴充套件字尾名,可以是多個,用逗號隔開,前面的優先
3 spl_autoload_extensions('.class.php,.php');4//
設定環境變數
5set_include_path(get_include_path().path_separator."libs/");6//
告訴php使用autoload函式自動裝載類
7spl_autoload_register();8//
可以使用
9$obj=new
test();
10//
輸出結果 loading class libs/test.class.php
__autoload()函式和自定義裝載函式
1load()函式可以不用require_once函式,可以使用spl_autoload函式<?php 2//
魔術方法自動裝載類,不用使用spl_autoload_register
3function __autoload($classname)6
//自定義裝載類,可以使用spl_autoload_register("load")自動呼叫
7function load($classname)10
11new test();//
輸出:loading class libs/test.php
1iii:autoload()執行流程function load($classname
)
二:其他函式
splfileinfo類和splfileobject類。
1三:課程總結<?php
2$file=new splfileinfo("demo.txt");3//
檔案建立時間
4echo "file is create at ".date("y-m-d h:i:s",$file->getctime())."";5
//檔案修改時間
6echo "file is modified at ".date("y-m-d h:i:s",$file->getmtime())."";7
//檔案大小
8echo "file size is ".$file->getsize()." bytes";9
//讀取檔案內容
10$fileobj=$file->openfile("r");
11while($fileobj->valid())
15$fileobj=null;//
關閉檔案,必要
16$file=null;//
關閉檔案,必要
upupw Apache Php5 5 的使用
2 1 解壓到 磁碟,我的是e盤,解壓後目錄結構如下 3 1 以管理員方式 執行 upupw exe,出現一下介面 3 2 輸入s1 開啟服務,這裡可能出現錯誤,可能是因為你 80埠和資料庫的3306埠的服務已經啟動或者被佔用, 可以先將這些服務停止,通過 s1 來啟動,也有可能 80埠 被 ...
CuteEditor 5 0 的使用
一篇比較好的文章 cuteeditor 5 0的安裝及它與ajax net配合無重新整理運算元據庫 優點 配置簡單,功能強大 fckedit...
Git的使用 5 在IDEA上使用
前言 idea中鼓搗git是真的費勁,建議還是用tortoisegit。 開啟idea的settings,左側選單列表中的version control裡面找到git。 只需要在 path to git executable 中選擇git安裝目錄的git exe檔案即可,其他的保持預設即可。 點選路...