class PHPExcel_Shared_File{protected static $_useUploadTempDirectory = FALSE;public static function sys_get_temp_dir() { if (self::$_useUploadTempDirectory) { // use upload-directory when defined to allow running on environments having very restricted // open_basedir configs if (ini_get('upload_tmp_dir') !== FALSE) { if ($temp = ini_get('upload_tmp_dir')) { if (file_exists($temp)) return realpath($temp); } } } // sys_get_temp_dir is only available since PHP 5.2.1 // http://php.net/manual/en/function.sys-get-temp-dir.php#94119 if ( !function_exists('sys_get_temp_dir')) { if ($temp = getenv('TMP') ) { if ((!empty($temp)) && (file_exists($temp))) { return realpath($temp); } } if ($temp = getenv('TEMP') ) { if ((!empty($temp)) && (file_exists($temp))) { return realpath($temp); } } if ($temp = getenv('TMPDIR') ) { if ((!empty($temp)) && (file_exists($temp))) { return realpath($temp); } } // trick for creating a file in system's temporary dir // without knowing the path of the system's temporary dir $temp = tempnam(__FILE__, ''); if (file_exists($temp)) { unlink($temp); return realpath(dirname($temp)); } return null; } // use ordinary built-in PHP function // There should be no problem with the 5.2.4 Suhosin realpath() bug, because this line should only // be called if we're running 5.2.1 or earlier return realpath(sys_get_temp_dir()); }}}
這是摘出來的一段代碼。兩個問題
1:protected static $_useUploadTempDirectory = FALSE; 恒假,那麼if (self::$_useUploadTempDirectory)這個判斷就不成立,為什麼還要寫這個if語句呢?
2:if ( !function_exists('sys_get_temp_dir')) 這個if語句就在sys_get_temp_dir函數中,也就是說這個函數一直存在啊?? 那麼下面的語句也就不會執行了啊
不知道我理解的對不對?? 這個也算是一個比較成熟的cms裡的代碼了。。 為什麼會這麼寫呢??
回複內容:
class PHPExcel_Shared_File{protected static $_useUploadTempDirectory = FALSE;public static function sys_get_temp_dir() { if (self::$_useUploadTempDirectory) { // use upload-directory when defined to allow running on environments having very restricted // open_basedir configs if (ini_get('upload_tmp_dir') !== FALSE) { if ($temp = ini_get('upload_tmp_dir')) { if (file_exists($temp)) return realpath($temp); } } } // sys_get_temp_dir is only available since PHP 5.2.1 // http://php.net/manual/en/function.sys-get-temp-dir.php#94119 if ( !function_exists('sys_get_temp_dir')) { if ($temp = getenv('TMP') ) { if ((!empty($temp)) && (file_exists($temp))) { return realpath($temp); } } if ($temp = getenv('TEMP') ) { if ((!empty($temp)) && (file_exists($temp))) { return realpath($temp); } } if ($temp = getenv('TMPDIR') ) { if ((!empty($temp)) && (file_exists($temp))) { return realpath($temp); } } // trick for creating a file in system's temporary dir // without knowing the path of the system's temporary dir $temp = tempnam(__FILE__, ''); if (file_exists($temp)) { unlink($temp); return realpath(dirname($temp)); } return null; } // use ordinary built-in PHP function // There should be no problem with the 5.2.4 Suhosin realpath() bug, because this line should only // be called if we're running 5.2.1 or earlier return realpath(sys_get_temp_dir()); }}}
這是摘出來的一段代碼。兩個問題
1:protected static $_useUploadTempDirectory = FALSE; 恒假,那麼if (self::$_useUploadTempDirectory)這個判斷就不成立,為什麼還要寫這個if語句呢?
2:if ( !function_exists('sys_get_temp_dir')) 這個if語句就在sys_get_temp_dir函數中,也就是說這個函數一直存在啊?? 那麼下面的語句也就不會執行了啊
不知道我理解的對不對?? 這個也算是一個比較成熟的cms裡的代碼了。。 為什麼會這麼寫呢??
1 static 只是靜態 ,但是可以被修改的
2 sys_get_temp_dir 指的是php系統內建的函數,而不是類中的函數
有沒有想過,它的繼承類可能把$_useUploadTempDirectory設成true?