自从我完成任何繁重的PHP开发以来已经有一段时间了。我正在尝试使用composer
和namespaces
更新旧图书馆,并且很难完全了解事情。
这是我的composer.json
{
"description": "MyClass",
"require": {
"php": ">=5.3.0",
"guzzlehttp/guzzle": "~6.0"
},
"autoload": {
"psr-4": {
"MyClass\\": "src/"
}
}
}
我正在尝试编写一些有关如何使用更新库的示例,但我无法运行代码。这是我的示例文件:
<?php
use MyClass;
$account_id = 123; // Replace with your account id
$public_key = '09876'; // Replace with your public key
$private_key = 'privkey'; // Replace with your private key
$klass = new MyClass($account_id, $public_key, $private_key);
echo $klass->myMethod();
每次运行上面的代码时,都会出现以下错误:
Warning: The use statement with non-compound name 'MyClass' has no effect
PHP Fatal error: Class 'MyClass' not found