Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
访问php类中的配置文件数据_Php_Oop_Configuration - Fatal编程技术网

访问php类中的配置文件数据

访问php类中的配置文件数据,php,oop,configuration,Php,Oop,Configuration,我构建了一个类文件,其中包含一个函数,其中包含各种错误。我想将该函数移到config.php文件中 现在在config.php中如何继续使用该函数 职能: private function error($errnum=1000) { $data = array( '1000' => 'Required parameter is missing', '1100' => 'Parameter not recognized', '20

我构建了一个类文件,其中包含一个函数,其中包含各种错误。我想将该函数移到config.php文件中

现在在config.php中如何继续使用该函数

职能:

private function error($errnum=1000) {
    $data = array(
        '1000' => 'Required parameter is missing',
        '1100' => 'Parameter not recognized',
        '2000' => 'Currency type not recognized',
        '2100' => 'Currency amount must be to 2 decimal places',
        '2200' => 'Currencies cannot be the same',      
        '3000' => 'Service currently unavailable',
        '3100' => 'Error in service'
    );  
    $this->result($data[$errnum], $errnum);
} 
我尝试使用:

需要_一次(“config/config.php”)

在类文件中,但仍显示错误


解析错误:语法错误,意外的T_PRIVATE

public、protected和PRIVATE仅在类内需要。你的函数不是一个方法,而是一个独立的函数,因此私有函数在那里是无效的。将其移动到类中或删除关键字。

公共、受保护和私有仅在类中需要。你的函数不是一个方法,而是一个独立的函数,因此私有函数在那里是无效的。将其移动到类中或删除关键字。

如果在Config.php文件中使用它,则必须删除私有部分

然后必须包含用于显示结果的类实例。或者您必须替换
$this->result($data[$errnum],$errnum)用于不在类中的内容

举个例子:

function error($errnum=1000) {
    $data = array(
        '1000' => 'Required parameter is missing',
        '1100' => 'Parameter not recognized',
        '2000' => 'Currency type not recognized',
        '2100' => 'Currency amount must be to 2 decimal places',
        '2200' => 'Currencies cannot be the same',      
        '3000' => 'Service currently unavailable',
        '3100' => 'Error in service'
    );  
    echo "Error: ".$data[$errnum]."(".$errnum.")";
}

error(2000);

希望有帮助。

如果在Config.php文件中使用它,则必须删除私有部分

然后必须包含用于显示结果的类实例。或者您必须替换
$this->result($data[$errnum],$errnum)用于不在类中的内容

举个例子:

function error($errnum=1000) {
    $data = array(
        '1000' => 'Required parameter is missing',
        '1100' => 'Parameter not recognized',
        '2000' => 'Currency type not recognized',
        '2100' => 'Currency amount must be to 2 decimal places',
        '2200' => 'Currencies cannot be the same',      
        '3000' => 'Service currently unavailable',
        '3100' => 'Error in service'
    );  
    echo "Error: ".$data[$errnum]."(".$errnum.")";
}

error(2000);

希望有帮助。

谢谢。我删除了私人文件。但是,我在尝试访问该函数时仍然遇到错误。返回$this->错误(1000);这就是我用的。有什么不对吗?
$这个
也只在类中有意义。谢谢。我删除了私人文件。但是,我在尝试访问该函数时仍然遇到错误。返回$this->错误(1000);这就是我用的。这有什么不对?
$this
也只在类中有意义。我还想指出,
error
对于一个函数来说是一个稍微过于通用/模糊的名称。我还想指出,
error
对于一个函数来说是一个稍微过于通用/模糊的名称。