首页 > 解决方案 > 致命错误:未捕获的错误:找不到类“EthereumRPC\EthereumRPC”

问题描述

我已经玩了几个小时了,找到了各种自动加载器,但我想不通:

declare(strict_types=1);

function __autoload($class_name) 
{
    //class directories
    $directorys = array(
        'EthereumRPC/',
        'EthereumRPC/API/',
        'EthereumRPC/API/Personal/',
        'EthereumRPC/Contracts/',
        'EthereumRPC/Contracts/ABI/',
        'EthereumRPC/Exception/',
        'EthereumRPC/Response/',
        'ERC20/',
        'ERC20/data/',
        'ERC20/Exception/'
    );

    //for each directory
    foreach($directorys as $directory)
    {
        //see if the file exsists
        if(file_exists($directory.$class_name . '.php'))
        {
            require_once($directory.$class_name . '.php');
            //only require the class once, so quit after to save effort (if you got more, then name them something else 
            return;
        }            
    }
}

use EthereumRPC\EthereumRPC;
use ERC20\ERC20;

我加载了每个包含类的目录,但仍然出现错误:

致命错误:未捕获的错误:在 /home/sewicumg/public_html/contenthourlies.com/wp-content/themes/seoexp/account_client.php:62 中找不到类“EthereumRPC\EthereumRPC”

说明文件说只包括底部的两行,但这绝对行不通。

我错过了什么吗?

这是使用这些类的代码:

$geth = new EthereumRPC('127.0.0.1', 8545);
$erc20 = new ERC20($geth);

所有这些 EthereumRPC 和 ERC20 文件夹都与此代码所在的 php 文件位于同一目录中。

我在这里错过了什么吗?

标签: phpclassautoload

解决方案


推荐阅读