我遇到的问题是一个奇怪的问题,日志文件说我的类中名为“上传”的 __construct 方法是私有的,但实际上它是公共的!所以这个错误没有意义。这是我的课程代码;
class Upload
{
public $Errors;
public $ImageTypes;
public $CDN_URL;
public $UploadPath;
private $MaxHeight;
private $MaxWidth;
private $MaxTokenLength;
private $ForceMaxDimensions;
private $MaxFileSize = 5;
public function __construct()
{
include_once 'config.php';
$this->ImageTypes = array('JPG', 'PNG');
$this->Errors = array();
# convert from megabytes to bytes
$this->MaxFileSize = $this->MaxFileSize * 1048576;
}
}
这就是我开始上课的方式;
include_once 'upload.php';
$Upload = new Upload;
这是我的日志文件中的错误;
PHP Fatal error: Call to private Upload::__construct() from invalid context
我在网上查看了很多答案,但都没有帮助我,所以我非常希望 Stackoverflow 的答案!谢谢你的帮助。
编辑:config.php 文件的内容
$ImageTypes = array('JPG', 'PNG');
$CDN_URL = 'CDN.php';
$UploadPath = 'uploads/';
$MaxHeight = 1000;
$MaxWidth = 1000;
$ForceMaxDimensions = TRUE;
$MaxFileSize = 5;// Mb