基於PHP選項與資訊函數的使用詳解_php執行個體

來源:互聯網
上載者:User
bool assert ( mixed $assertion [, string $description ] ) — 檢查一個斷言是否為 FALSE
複製代碼 代碼如下:
assert_options(ASSERT_ACTIVE, true);//允許使用assert()函數
assert_options(ASSERT_WARNING, false);//在assert失敗時不輸出警告資訊
assert_options(ASSERT_BAIL, true);//assert失敗後終止代碼執行
assert_options(ASSERT_CALLBACK, 'getMsg');//assert失敗後終止代碼執行。

echo '開始:
';
assert('mysql_query("")');
echo '測試成功!';

function getMsg(){
echo '出錯啦!';
}

mixed assert_options ( int $what [, mixed $value ] ) — 設定 assert() 的各種控制選項,或者查詢當前的設定
ASSERT_ACTIVE : 是否啟用 assert() 斷言, ini配置 assert.active,預設值 1
ASSERT_WARNING :是否為每個失敗的斷言產生一個 PHP 警告,ini配置 assert.warning,預設1
ASSERT_BAIL :是否在宣告失敗時中止執行,ini配置 assert.bail,預設值0
ASSERT_QUIET_EVAL :是否在斷言運算式求值時禁用 error_reporting,ini配置assert.quiet_eval,預設值0
ASSERT_CALLBACK :宣告失敗時調用回呼函數,ini配置assert.callback
複製代碼 代碼如下:
assert_options(ASSERT_ACTIVE, true);//允許使用assert()函數
assert_options(ASSERT_WARNING, false);//在assert失敗時不輸出警告資訊
assert_options(ASSERT_BAIL, true);//assert失敗後終止代碼執行
assert_options(ASSERT_CALLBACK, 'getMsg');//assert失敗後終止代碼執行。

echo '開始:
';
assert(is_int(1.2));//檢測結果為fales
echo '測試成功!';

function getMsg(){
echo '出錯啦!';
}

bool dl( string $library ) — 擷取 PHP 配置選項的值 載入指定的 PHP擴充
複製代碼 代碼如下:
if(!extension_loaded('sqlite')){//測試指定的擴充是否已經啟用
$prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
dl($prefix . 'sqlite.' . PHP_SHLIB_SUFFIX);
}

int gc_collect_cycles() — 強制收集所有現存的垃圾重複持續時間
void gc_disable ( void ) — 停用循環參考收集器
void gc_enable ( void ) — 啟用循環參考收集器
bool gc_enabled ( void ) — 返回循環參考計數器的狀態
string get_cfg_var ( string $option ) — 擷取 PHP 配置選項的值擷取 PHP 配置選項的值
string get_current_user ( void )— 擷取當前 PHP 指令碼所有者名稱
array get_defined_constants ([ bool $categorize = false ] )— 返回所有常量的關聯陣列
array get_extension_funcs ( string $module_name )— 返回模組函數名稱的數組
複製代碼 代碼如下:
print_r(get_extension_funcs("xml"));

string get_include_path ( void ) — 擷取當前的 include_path 配置選項
array get_included_files ( void )— 返回被 include 和 require 檔案名稱的 array
複製代碼 代碼如下:
include 'test1.php';
include_once 'test2.php';
require 'test3.php';
require_once 'test4.php';

$included_files = get_included_files();

foreach ($included_files as $filename){
echo "$filename\n";
}

array get_loaded_extensions ([ bool $zend_extensions = false ] )— 返回所有編譯並載入模組名的 array
bool get_magic_quotes_gpc ( void )— 擷取當前 magic_quotes_gpc 的配置選項設定
bool get_magic_quotes_runtime ( void ) — 擷取當前 magic_quotes_runtime 配置選項的啟用狀態
string getenv ( string $varname ) — 擷取一個環境變數的值
複製代碼 代碼如下:
$ip = getenv('REMOTE_ADDR');

int getlastmod ( void )— 擷取頁面最後修改的時間
int getmygid ( void )— 擷取當前 PHP 指令碼擁有者的 GID
int getmyinode ( void )— 擷取當前指令碼的索引節點(inode)
int getmypid ( void )— 擷取 PHP 進程的 ID
int getmyuid ( void )— 擷取 PHP 指令碼所有者的 UID
array getopt ( string $options [, array $longopts ] )— 從命令列參數列表中擷取選項
array getrusage ([ int $who = 0 ] ) — 擷取當前資源使用狀況
array ini_get_all ([ string $extension [, bool $details = true ]] ) — 擷取所有配置選項
複製代碼 代碼如下:
print_r(ini_get_all("pcre"));
print_r(ini_get_all());

string ini_get ( string $varname ) — 擷取一個配置選項的值
void ini_restore ( string $varname )— 恢複配置選項的預設值
string ini_set ( string $varname , string $newvalue )— 為一個配置選項設定值
main — 虛擬 main()int memory_get_peak_usage ([ bool $real_usage = false ] )— 返回分配給 PHP 記憶體的峰值int memory_get_usage ([ bool $real_usage = false ] ) — 返回分配給 PHP 的記憶體量
string php_ini_loaded_file ( void ) — 取得已載入的 php.ini 檔案的路徑
string php_ini_scanned_files ( void )— 返回從額外 ini 目錄裡解析的 .ini 檔案列表
string php_sapi_name ( void ) — 返回 網頁伺服器和 PHP 之間的介面類型
string php_uname ([ string $mode = "a" ] )— 返回運行 PHP 的系統的有關資訊
'a':此為預設all。
's':作業系統名稱
'n':主機名稱。例如: localhost.example.com。
'r':版本名稱,例如: 5.1.2-RELEASE。
'v':版本資訊。作業系統之間有很大的不同。
'm':機器類型。例如:i386。
bool phpcredits ([ int $flag = CREDITS_ALL ] ) — 列印 PHP 貢獻者名單
CREDITS_ALL :所有的
CREDITS_DOCS : 文檔組貢獻名單
CREDITS_FULLPAGE : 常用於和其他標誌進行組合。 表示需要列印包含其他標誌表示資訊的獨立 HTML 頁面。
CREDITS_GENERAL : 普遍名單:語言設計與理念、PHP作者以及 SAPI 模組
CREDITS_GROUP : 核心開發人員名單
CREDITS_MODULES : PHP 擴充模組以及作者
CREDITS_SAPI : PHP 的伺服器 API 模組以及作者
複製代碼 代碼如下:
phpcredits(CREDITS_GROUP | CREDITS_DOCS | CREDITS_FULLPAGE);

bool phpinfo ([ int $what = INFO_ALL ] ) — 輸出關於 PHP 配置的資訊
string phpversion ([ string $extension ] ) — 擷取當前的PHP版本
bool putenv ( string $setting )— 設定環境變數的值
void restore_include_path ( void ) — 還原 include_path 配置選項的值
string set_include_path ( string $new_include_path ) — 設定 include_path 配置選項
void set_time_limit ( int $seconds )— 設定指令碼最大執行時間,從它本身開始計時,0表示不限時
string sys_get_temp_dir ( void ) — 返回用於臨時檔案的目錄
mixed version_compare ( string $version1 , string $version2 [, string $operator ] ) — 對比兩個PHP 正常化的版本數字字串
複製代碼 代碼如下:
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
echo '我的PHP版本很高: ' . PHP_VERSION . "\n";
}

int zend_thread_id ( void ) — 返回當前線程的唯一識別符
string zend_version ( void ) — 擷取當前 Zend 引擎的版本
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.