【发布时间】:2019-01-22 07:51:17
【问题描述】:
我不能使用作曲家,所以我必须以不同的方式来做,最初我使用 require_once 来加载每个单独的类,但也没有成功,所以现在我正在使用自动加载器,但我仍然面临相同或相似的问题:
它开始的页面:
<?php
declare(strict_types=1);
require __DIR__ . '/ERC20/autoload.php';
use ERC20\ERC20;
use ERC20\EthereumRPC;
$geth = new EthereumRPC('127.0.0.1', 8545);
这是自动加载文件:
<?php
spl_autoload_register(function($class){
$path = __DIR__ . '/' . $class . '.php';
if(file_exists($path))
require $path;
});
?>
这些类存储在名为 ERC20 的文件夹中,该文件夹与客户端帐户 php 文件位于同一目录中。
这是它抛出的错误:
致命错误:未捕获的错误:类 'ERC20\EthereumRPC' 未在 /home/sewicumg/public_html/contenthourlies.com/wp-content/themes/seoexp/account_client.php:35
第 35 行是这一行:
$geth = new EthereumRPC('127.0.0.1', 8545);
文件 EthereumRPC.php 存在于 ERC20 文件夹中,我使用的是 PHP7.1
有人建议使用自动加载器,所以我就这么做了,但到目前为止无济于事。
【问题讨论】:
-
附加 var_dump($path)
-
string(99) "/home/sewicumg/public_html/contenthourlies.com/wp-content/themes/seoexp/ERC20/ERC20\EthereumRPC.php"
-
我也去掉了两条 use 行:use ERC20\ERC20;使用 ERC20\EthereumRPC;,这样它会打印正确的路径,但我仍然会遇到找不到类的错误。
-
你能告诉我们命名空间是如何在你的以太坊类中定义的吗?
-
string(93) "/home/sewicumg/public_html/contenthourlies.com/wp-content/themes/seoexp/ERC20/EthereumRPC.php" 致命错误:未捕获错误:未找到“EthereumRPC”类在 /home/sewicumg/public_html/contenthourlies.com/wp-content/themes/seoexp/account_client.php:34 堆栈跟踪:#0 /home/sewicumg/public_html/contenthourlies.com/wp-includes/template-loader.php (74): include() #1 /home/sewicumg/public_html/contenthourlies.com/wp-blog-header.php(19): require_once('/home/sewicumg/...')
标签: php class autoloader