即使文件存在,也找不到PHP类


PHP Class not found even though file exists

我研究了这个问题,发现了其他问题(PHP类没有找到,但它's包含),但他们没有回答这个愚蠢的简单问题!

错误:Class 'Functions' not found in /public_html/sites/sitename/index.php

我的文件夹结构如下:

public_html/assests/php/functions.php //class

I require_once this file from here: public_html/sites/sitename/index.php

我已经检查了file_exists,当然它会否则require_once会失败。这是怎么回事?!

这是我的代码(以防我遗漏了一些非常愚蠢的东西…)

    require_once('../../assets/php/functions.php'); 
    if( file_exists('../../assets/php/functions.php') ){
        error_log('Of course it exists!');
    }
    else{
        error_log('Oh dear...');
    }
    $fn = new Functions();

functions.php的内容(为简洁而编辑):

class Functions{    
    public function functions(){
        //constructor
    }
    //pretty print
    public function pp($str){
        return '<pre class="pre-show prettyprint">'.htmlentities($str).'</pre>';
    }
}

你有一个拼写错误,一个额外的s在'assets':

My folder structure is like this:
public_html/assests/php/functions.php //class

确保你的文件名是"assets"并确保你的require与之匹配:

require_once('../../assets/php/functions.php');