Uncaught Error: Class 'Office365\SharePoint\ClientContext' not found - php

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);

Related

Class Page Not Found in PHP Application

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.

Namespace with extends or interface causes Fatal Error without autoloader

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();

request.CRITICAL: Uncaught PHP Exception Compile Error: Cannot declare class

I use the following two classes with the same name.
/src/AppBundle/Qrcode.php
namespace AppBundle\Qrcode;
use Endroid\QrCode\QrCode;
class Qrcode
{
And
/vendor/Endroid/.../Qrcode.php
namespace Endroid\QrCode;
use Endroid\QrCode\Exceptions\DataDoesntExistsException;
use Endroid\QrCode\Exceptions\VersionTooLargeException;
use Endroid\QrCode\Exceptions\ImageSizeTooLargeException;
use Endroid\QrCode\Exceptions\ImageFunctionUnknownException;
use ReflectionFunction;
class QrCode
{
on the dev it works well but not on the prod one as I receive the following error message:
request.CRITICAL: Uncaught PHP Exception
Symfony\Component\Debug\Exception\FatalErrorException: "Compile Error:
Cannot declare class AppBundle\Qrcode because the name is
already in use" at .../src/AppBundle/Qrcode.php line 8.
I don't understand why it doesn't work. The namespaces are different and
It works on the dev part...
Thanks
You need to differentiate class with alias because QrCode Class is loaded twice.
In, /src/AppBundle/Qrcode.php
namespace AppBundle\Qrcode;
use Endroid\QrCode\QrCode as EndroidQr // assign alias here to differnciate class
after this, new EndroidQr(); would instantiate a Endroid\QrCode\QrCode Class
Note:- If you want to load one class in a file who has same class name then you need to assign alias.
Hope it will help you :-)

Upload files using Zend Error

I am trying to upload files following Zend's tutorial, but keep getting this error:
[10-Apr-2015 05:14:41 Europe/Berlin] PHP Fatal error: Class 'Album\Controller\UploadForm' not found in /Applications/MAMP/htdocs/zf2-tutorial/module/Album/src/Album/Controller/AlbumController.php on line 120
Look like you forgot to use Your UploadForm class on top of controller class. So in that case when you call directly call Form class from controller it searched into current namespace which is Album\Controller so error coming.
Change it to (Assuming your form class at Album/Form/).
namespace Album\Controller;
use Album\Form\UploadForm;

Unable to access "use"d class in function

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 ?

Categories