[英]php Class calling a function inside another function error
I have the following class with few functions inside. 我有以下课程,里面没有几个功能。 I'm getting an error when i call the
get_dir_size()
inside the Diskspace()
function. 我在
get_dir_size()
Diskspace()
函数内调用get_dir_size()
时出现错误。 It's not recognizing it. 它没有意识到。 What am i doing wrong.
我究竟做错了什么。 This code is for creating an expressionengine plugin.
该代码用于创建一个expressionengine插件。
Fatal error: Call to undefined function get_dir_size() 致命错误:调用未定义的函数get_dir_size()
class DiskSpace
{
public $return_data = "";
public function Diskspace()
{
$this->EE =& get_instance();
$dir_name = $_SERVER['DOCUMENT_ROOT']."/userfiles/";
/* 1048576 bytes == 1MB */
$total_size= round((get_dir_size($dir_name) / 1048576),2) ;
$this->return_data = $total_size;
}
public function get_dir_size($dir_name){
$dir_size =0;
if (is_dir($dir_name)) {
if ($dh = opendir($dir_name)) {
while (($file = readdir($dh)) !== false) {
if($file !="." && $file != ".."){
if(is_file($dir_name."/".$file)){
$dir_size += filesize($dir_name."/".$file);
}
/* check for any new directory inside this directory */
if(is_dir($dir_name."/".$file)){
$dir_size += get_dir_size($dir_name."/".$file);
}
}
}
}
}
closedir($dh);
return $dir_size;
}
}
Change the line that calls get_dir_size($dir_name) to :- 将调用get_dir_size($ dir_name)的行更改为:-
$total_size= round(($this->get_dir_size($dir_name) / 1048576),2) ;
There are a few more issues with this code What is this ? 此代码还有更多问题,这是什么?
$this->EE = & get_instance();
and also you will get errors when you execute closedir($dh);
而且,当您执行
closedir($dh);
时也会出错closedir($dh);
if the if
statement that it is declared in is not executed. 如果声明所在的
if
语句未执行。
Remember when you call objects own function inside the object, use the $this pointer variable. 请记住,当您在对象内部调用对象自己的函数时,请使用$ this指针变量。
$total_size= round((get_dir_size($dir_name) / 1048576),2) ;
Change to 改成
$total_size= round(($this->get_dir_size($dir_name) / 1048576),2) ;
Would be also good if you told us which line the error is happening at. 如果您告诉我们错误发生在哪一行,那也很好。 Would be also nice to see the full error log.
看到完整的错误日志也将很高兴。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.