The bootstrap script contains
use Aws\Common\Aws;
use Aws\S3\Enum\CannedAcl;
use Aws\S3\Exception\S3Exception;
I have a function "aws_s3_put_object" with the code
$s3 = Aws::factory('../lib/aws-config.php')->get('s3');
but I get the error
PHP Fatal error: Class 'Aws' not found
Why is the class "Aws" not accessible in the function ? What am I doing wrong ?
Related
I'm new to php and I get the following error:
Uncaught Error: Class 'Office365\SharePoint\ClientContext' not found.
while calling one of the class static methods from inside another class called 'sharepoint'.
I checked if the class exists via the "class_exists" function, and indeed it is.
And I also checked if the autoload file path is correct via the file_exists function, also correct.
this is the start of the file:
namespace sogo;
require_once 'vendor/autoload.php';
use Office365\Runtime\Auth\UserCredentials;
use Office365\SharePoint\ClientContext;
and this is the code that call the class (its inside a method of another class):
$ctx = ClientContext::connectWithUserCredentials($this->api_base_url,$this->userName,$this->password);
PHP Application running as docker container throws below error under increased load. Unable to figure out the root cause. Any advice would help?
PHP Fatal error: Uncaught Error: Class 'Page' not found in /var/www/html/vendor/silverstripe/errorpage/src/ErrorPage.php
This is the code of ErrorPage.php:
<?php
namespace SilverStripe\ErrorPage;
use Page;
use SilverStripe\Assets\File;
use SilverStripe\Assets\Storage\GeneratedAssetHandler;
use SilverStripe\CMS\Controllers\ModelAsController;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\Debug;
class ErrorPage extends Page
{
.....
}
The Page class is imported with use Page;.
Is there a file named Page.php in the same folder as SilverStripe/ErrorPage.php?
If not then that's the problem and use Page; is not correct and should be changed to the correct path or the file should be created with correct code.
In the same direcory I have:
html/app
Plugin.php
PluginContract.php
GetUid.php
On GetUid.php i have this code:
<?php
namespace App;
include_once "Plugin.php";
include_once "PluginContract.php";
use Carbon\Carbon;
use TeamSpeak3\Ts3Exception;
class GetUid extends Plugin implements PluginContract
{
public function isTriggered()
{
...
}
}
And this is PluginContract.php:
<?php
namespace App;
interface PluginContract
{
public function isTriggered();
}
It seems all ok, but I got this error:
PHP Fatal error: Interface 'App\PluginContract' not found in /var/www/html/app/GetUid.php on line 11
The weird thing is that it can load Plugin.php without problem but it gets this error for PluginContract.php which is in the same folder.
What I'm doing wrong?
What I was tring to do is add a web interface to a PHP application, I though that I don't need the autoload because it automatically start with the server, but I discovered that adding again the autoload to my index.php I resolved the problem.
Why doesn't this work?
web/index.php (Not web/src/App/App.php)
<?php
namespace App;
// web/index.php
require_once __DIR__ . '/../vendor/autoload.php';
$app = new App();
class App extends \Silex\Application {
public function __construct()
{
parent::__construct();
echo 'Worked!';
}
}
I also tried namespace App {...}, no change. It throws this exception:
Fatal error: Uncaught Error: Class 'App\App' not found in /path/to/web/index2.php:8
Stack trace:
#0 {main}
thrown in /path/to/web/index2.php on line 8
As long as I remove the extends ... and the parent call part, it works. I also noticed interface does the same thing (trying to use Serializable). Is this an issue with the autoloader being confused? Is there a way to do this without putting the App\App class into a file in src\App\App.php?
Note: this is an exercise to build a single-file application with Silex, so "just put it in a file" isn't an answer. I want to know why this doesn't work, which has an answer.
The problem in your code is,
In namespace, You are initiating class object before it being declared and loaded. In your above code you are doing same thing,
1. You are initiating App class object which lies in App namespace
2. You are initiating class object at the moment class when is not yet declared(As it is defined below in your code).
In your above code, not even your loader be called. It will be called if you initiate App\App class object after its declaration. and If your loader does not work fine then afterwards you will possibly get this error.
Fatal Error: Silex\Application class not found
Please checkout some examples and findings.
Example 1 Here loader is expected to be called but not called, because you have registered after initialization of class($app = new App();).
Example 2 Here, calling class will look for autoloading class because here initialization takes place after registration of loader and declaration of class, which is probably answers your question.
Change your code with this to get it fix:
<?php
namespace App;
require_once __DIR__ . '/../vendor/autoload.php';
class App extends \Silex\Application {
public function __construct()
{
parent::__construct();
echo 'Worked!';
}
}
$app = new App();
Trying to implement a 3rd-party-lib with PHP 5.3.9-ZS5.6.0 and the lib uses namespaces. The code where I want to use the lib doesn't. So i have:
facebook.php
Mute
(Mute is the folder of the lib)
In facebook.php I try:
$app = new \Mute\Facebook\App();
Resulting in: Fatal error: Class 'Mute\Facebook\App' not found in...
The files are all in place.
I can say:
use \Mute\Facebook\App;
without getting any error/warning... What am I missing?
When I require the "App.php" via require_once I get the next error: Fatal error: Interface 'Mute\Facebook\Bases\AccessToken' not found in [...]/Mute/Facebook/App.php
Mute/Facebook/App.php:
<?php
namespace Mute\Facebook;
use Closure;
use Exception;
use Mute\Facebook\Bases\AccessToken;
use Mute\Facebook\Bases\Batchable;
use Mute\Facebook\Bases\Configurable;
use Mute\Facebook\Bases\Requestable;
use Mute\Facebook\Bases\RequestHandler;
use Mute\Facebook\Exception\CurlException;
use Mute\Facebook\Exception\GraphAPIException;
use Mute\Facebook\Exception\HTTPException;
use Mute\Facebook\Exception\InvalidArgumentException;
use Mute\Facebook\Exception\OAuthSignatureException;
use Mute\Facebook\Util;
class App implements AccessToken, Batchable, Configurable, Requestable, RequestHandler
{ [...]
function __autoload($class_name) {
require_once str_replace('\\', '/', $class_name) . '.php';
}
I created a __autoload function to "magically" require all files I need. Totally forgot about this method >.<