You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP报错:Uncaught Error: App\Feed\Contabeis类未找到(路径已确认)

PHP 类 "App\Feed\Contabeis" 找不到的排查方案

问题描述

已确认类导入路径正确,但仍触发Uncaught Error: Class "App\Feed\Contabeis" not found错误。

使用类的代码(/home/carlosszpiro/Documentos/Estudos/PHP/RSS/includes/feed.php)

<?php

use \App\Feed\Contabeis;

$obFeed = new Contabeis;

类定义代码

<?php 

namespace App\Feed;

class Contabeis {
  const FEED_URL = 'https://www.contabeis.com.br/rss/conteudo/';

  private $feed = null;

  public function __construct() {
    $this->loadFeed();
  }

  private function loadFeed() {
    $curl = curl_init();

    curl_setopt_array($curl, [
      CURLOPT_URL => self::FEED_URL,
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_CUSTOMREQUEST => 'GET',
    ]);

    $response = curl_exec($curl);
    curl_close($curl);

    return $this->parseXML($response);
  
  }

  private function parseXML($response) {
    if(!strlen($response)) return false;

    $this->feed = simplexml_load_string($response);

    return true;
  }

  public function getTitle() {
    return $this->feed->channel->title;
  }

  public function getItems() {
    return $this->feed->channel->item;
  }

}

错误信息

[::1]:53700 [200]: GET / - Uncaught Error: Class "App\Feed\Contabeis" not found in /home/carlosszpiro/Documentos/Estudos/PHP/RSS/includes/feed.php:5
Stack trace:
#0 /home/carlosszpiro/Documentos/Estudos/PHP/RSS/index.php(6): require()
#1 {main} thrown in /home/carlosszpiro/Documentos/Estudos/PHP/RSS/includes/feed.php on line 5

排查与解决步骤

  • 验证文件结构匹配命名空间
    命名空间App\Feed要求类文件必须放在项目根目录下的App/Feed/文件夹内,且文件名必须为Contabeis.php(Linux系统严格区分大小写)。检查你的文件路径是否为:
    /home/carlosszpiro/Documentos/Estudos/PHP/RSS/App/Feed/Contabeis.php
    若路径或文件名不符,调整后重试。

  • 配置自动加载机制

    • 若使用Composer,确保composer.json中包含PSR-4自动加载规则:
      {
        "autoload": {
          "psr-4": {
            "App\\": "App/"
          }
        }
      }
      
      执行composer dump-autoload更新自动加载映射,并在入口文件index.php顶部引入自动加载文件:
      require __DIR__ . '/vendor/autoload.php';
      
    • 若未使用Composer,需在feed.php中手动引入类文件,根据实际路径调整:
      require __DIR__ . '/../App/Feed/Contabeis.php'; // 示例路径,需根据实际结构修改
      
  • 检查大小写一致性
    Linux环境下,类名Contabeis与文件名Contabeis.php的大小写必须完全一致,避免因小写文件名导致类无法被识别。

  • 确认文件权限
    确保Web服务器进程拥有读取Contabeis.php文件的权限,建议将文件权限设置为644,文件夹权限设置为755。

内容的提问来源于stack exchange,提问作者Carlos Szpiro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 00:10:34