I'm not able to use composer so I have to do it in a different way, initially I used require_once to load every individual class but that didn't work out either so now I'm using an autoloader instead but I still face the same or similar problems:
The page where it starts:
<?php
declare(strict_types=1);
require __DIR__ . '/ERC20/autoload.php';
use ERC20\ERC20;
use ERC20\EthereumRPC;
$geth = new EthereumRPC('127.0.0.1', 8545);
This is the autoload file:
<?php
spl_autoload_register(function($class){
$path = __DIR__ . '/' . $class . '.php';
if(file_exists($path))
require $path;
});
?>
The classes are stored in a folder named ERC20 that's in the same directory as the Client account php file.
This is the error it throws:
Fatal error: Uncaught Error: Class 'ERC20\EthereumRPC' not found in /home/sewicumg/public_html/contenthourlies.com/wp-content/themes/seoexp/account_client.php:35
Line 35 is this line:
$geth = new EthereumRPC('127.0.0.1', 8545);
The file EthereumRPC.php is present in the folder ERC20, and I'm using PHP7.1
Someone suggested to use an autoloader so that's what I did but to no avail thus far.
I fixed it by creating a new folder named Vendor, moved the ERC20 folder in that folder and moved the autoload.php there as well.
I also used a different autoload that I found on Youtube, and now all the classes get loaded without error.
This is the the autoload code:
<?php
spl_autoload_register(function($class){
$prefix = 'ERC20\\';
$length = strlen($prefix);
$path = __DIR__ . '/ERC20/';
if (strncmp($prefix, $class, $length) !==0) {
return;
}
$relative_class = substr($class, $length);
$file = $path . str_replace ('\\', '/', $relative_class) . '.php';
if(file_exists($file)) {
require $file;
}
});
?>
And this is how I call the autoload in the page:
require 'vendor/autoload.php';
Firebase Cloud Functions: PubSub, "res.on is not a function"
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
I am currently working within CodeIgniter and I am struggling to understand how to properly use Anemic or Rich Entity Classes within my programming
This question already has an answer here:
I havew for example 'employees' table and 'phones' tables , now i select them together