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 :-)
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.
Trying to build a simple oop solution but can't understand why I can't instantiate this class. I'm using an interface, class and implementing the class on an index.php but I'm getting a not found class error. What am I doing wrong?
Interface:
namespace interfaces;
interface ISales
{
}
Class:
namespace classes;
use interfaces\iSales;
class Sales implements iSales
{
}
Implementation (index.php):
use classes\Sales;
$sales = new Sales();
Error:
PHP Fatal error: Uncaught Error: Class 'classes\Sales' not found in ...
Error: Class 'classes\Sales' not found in
Thanks for all the comments. I've just used composer for that using this example: https://enterprise-level-php.com/2017/12/25/the-magic-behind-autoloading-php-files-using-composer.html
I'm coming from C# so PHP works a little bit different.
this page has encountered the following error:
Fatal error: Class 'JAccessRule' not found in
/home/www/newporttours.dk/libraries/legacy/access/rule.php on line 22
I tried replacing this
class JRule extends JAccessRule
{
With this
class JAccessRule
{
On line 22. Then the frontend just returned "JAccessRule cannot be resolved"
I have no idea about the history of this site, if someone tried to upgrade it or what. I just had it handed down.
Please help :-)
This is a PHP error which happens when you try to use a class. When you say that
class JRule extends JAccessRule
{
then you essentially say that JRule inherits JAccessRule, but since your JAccessRule class is not loaded when this file is loaded, you get the error. You need to require_once the location of the file which contains JAccessRule before you define this class.
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;