Does PHP code write this superfluous??

Source: Internet
Author: User
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 en Vironments having very restricted//Open_basedir configs if (ini_get (' Upload_tmp_dir ')!== FAL                        SE) {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/FU  nction.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 is no problem with the 5.2.4 Suhosin Realpath () b UG, because this line should only//is called if we ' re running 5.2.1 or earlier return Realpath (Sys_    Get_temp_dir ()); }}}

This is a piece of code that is picked out. Two questions
1:protected static $_useuploadtempdirectory = FALSE; Constant false, then if (self::$_useuploadtempdirectory) This judgment is not tenable, why still write this if statement?

2:if (!function_exists (' Sys_get_temp_dir ')) this if statement is in the Sys_get_temp_dir function, that is to say, this function always exists ah?? Then the following statement will not be executed.

I don't know, I understand, right? This is also a relatively mature CMS code. Why do you write this??

Reply content:

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 en Vironments having very restricted//Open_basedir configs if (ini_get (' Upload_tmp_dir ')!== FAL                        SE) {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/FU  nction.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 is no problem with the 5.2.4 Suhosin Realpath () b UG, because this line should only//is called if we ' re running 5.2.1 or earlier return Realpath (Sys_    Get_temp_dir ()); }}}

This is a piece of code that is picked out. Two questions
1:protected static $_useuploadtempdirectory = FALSE; Constant false, then if (self::$_useuploadtempdirectory) This judgment is not tenable, why still write this if statement?

2:if (!function_exists (' Sys_get_temp_dir ')) this if statement is in the Sys_get_temp_dir function, that is to say, this function always exists ah?? Then the following statement will not be executed.

I don't know, I understand, right? This is also a relatively mature CMS code. Why do you write this??

1 static only, but can be modified
2 Sys_get_temp_dir refers to a function that comes with a PHP system, not a function in a class

Have you ever thought that its inheriting class might set $_useuploadtempdirectory to true?

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.