如何在另一个文件类中调用类及其函数


how to call a class and its function in another file class

   include 'upload.php';
   $attachments = new $uploads();
   $file = $uploads->uploadAttachment();
   $this->file->uploadAttachment();
上传

是上传中的类名。php 文件。在这里我收到此错误:

  Notice: Undefined variable
  Fatal error: Class name must be a valid object or a string 

请帮助我做错的地方

你在初始化类时uploads();之前放了一个 $,你需要使用确切的类名,所以这应该可以工作:$attachments = new uploads();

类名不使用$字符。您需要这样做:

$attachments = new Uploads();

new $uploads()实际上意味着"创建变量$uploads中命名的类的新对象"。由于$uploads是未定义的,因此不会创建任何类,并且会抛出您看到的错误。