• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php代码这样写是不是多此一举??

php 搞代码 3年前 (2022-01-25) 18次浏览 已收录 0个评论
文章目录[隐藏]
<code>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());    }}}</code>

这是摘出来的一段代码。两个问题
1:protected static $_useUploadTempDirectory = FALSE; 恒假,那么if (self::$_useUploadTempDirectory)这个判断就不成立,为什么还要写这个if语句呢?

2:if ( !function_exists(‘sys_get_temp_dir’)) 这个if语句就在sys_get_temp_dir函数中,也就是说这个函数一直存在啊?? 那么下面的语句也就不会执行了啊

不知道我理解的对不对?? 这个也算是一个比较成熟的cms里的代码了。。 为什么会这么写呢??

回复内容:

<code>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<p>5本文来源gao!daima.com搞$代!码#网#</p><pre>搞代gaodaima码

.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?


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php代码这样写是不是多此一举??

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址