I am using
php 7.4.3
composer v4.1.4
I have this error
Fatal error: Uncaught Error: Call to undefined method Dotenv\Dotenv::createImmutable() in C:\xampp\htdocs\ecommerce\app\config\_env.php:9
Stack trace:
#0 C:\xampp\htdocs\ecommerce\bootstrap\init.php(8): require_once()
#1 C:\xampp\htdocs\ecommerce\public\index.php(3): require_once('C:\\xampp\\htdocs...')
#2 {main} thrown in C:\xampp\htdocs\ecommerce\app\config\_env.php on line 9
Define base path
_env.php ------------> any other method of defining realpath?
<?php
define('BASE_PATH', realpath(__DIR__.'/../../'));
require_once __DIR__.'/../../vendor/autoload.php';
$dotEnv = Dotenv\Dotenv::createImmutable(BASE_PATH);
$dotEnv->load();
index.php
<?php
require_once __DIR__ . '/../bootstrap/init.php';
$app_name = getenv('APP_NAME');
echo $app_name;
Related
My code, script start.php in app folder:
require __DIR__ . '../../dropbox-php-sdk-master/vendor/autoload.php';
session_start();
$_SESSION['user_id'] = 1;
$dropboxKey = '';
$dropboxSecret = '';
$appName = '';
$appInfo = new Dropbox\AppInfo($dropboxKey,$dropboxSecret);
My folder structure:
1.app
1.1. start.php
2.dropbox-php-sdk-master
2.1.vendor
2.1.1. autoload.php
3.index.php (calls function start.php)
And when I call the index.php i recive this erro:
Fatal error: Uncaught Error: Class 'Dropbox\AppInfo' not found in C:\xampp\htdocs\tutorials\dropboxapi\app\start.php:12 Stack trace: #0 C:\xampp\htdocs\tutorials\dropboxapi\index.php(3): require() #1 {main} thrown in C:\xampp\htdocs\tutorials\dropboxapi\app\start.php on line 12
I follow some tutorials on the internet and they all have the same structure, what Im doing bad?
I use this code:
require_once __DIR__."/vendor/autoload.php";
use League\OAuth2\Server\AuthorizationServer;
use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\Grant\PasswordGrant;
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
$clientRepository = new ClientRepository();
But I get error :
Fatal error: Uncaught Error: Class 'ClientRepository' not found in
/home/a/public_html/app/oauth2.php:23 Stack trace: #0 {main} thrown in
/home/a/public_html/app/oauth2.php on line 23
Maybe, you forgot namespace:
require_once __DIR__."/vendor/autoload.php";
use League\OAuth2\Server\AuthorizationServer;
use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\Grant\PasswordGrant;
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
use NamespaceClass\ClientRepository; <-- edit
$clientRepository = new ClientRepository();
I wrote an autoloader class.
But the include_once function does not include the file I need.
Cls.php(path:cls/)
<?php
class fileup{
function dup($a){
$x=strip_tags($a);
$d=__DIR__."/".$x.".cls.php";
echo $d; ///storage/emulated/legacy/htdocs/yeni/sinif/ayar.sinif.php
if(file_exists($d)){
include_once $d;
}else{
die($a." Class not found :(");
}
}
}
$dup=new fileup();
spl_autoload_register(array($dup,"dup"));
?>
Theme.cls.php Theme class (path:cls/)
<?php
include_once("cls.php");
$dup->dup("conf");
?>
Conf.cls.php Site config class (path:cls/)
<?php include_once("cls.php"); $dup->dup("db"); ?>
index.php (path:/)
<?php
include_once("theme.cls.php");
?>
Error details:
Fatal error: Uncaught Error:
Call to a member function dup() on null in /storage/emulated/legacy/htdocs/yeni/sinif/conf.cls.php:3
Stack trace:
#0 /storage/emulated/legacy/htdocs/yeni/sinif/cls.php(12):
**include_once() #1**
/storage/emulated/legacy/htdocs/yeni/sinif/theme.cls.php(3):
dup->dup('conf') #2
/storage/emulated/legacy/htdocs/yeni/index.php(2):
include_once('/storage/emulat...') #3
{main} thrown inĀ /storage/emulated/legacy/htdocs/yeni/sinif/conf.cls.php on lineĀ 3
I am trying autoload function in php. The files are all in the same directory.
I have a file called aviation.php with the following code:
class Avaitor{
public function __construct(){
echo "Fly high<br>";
}
}
Then in my autoloader file I am trying to do this:
function __autoload($fileName){
if(file_exists($fileName . ".php"))
require_once $fileName . ".php";
}
//require_once "aviatior.php";
$pilot = new Avaitor();
But I am getting this error:
Fatal error: Uncaught Error: Class 'Avaitor' not found in
/Applications/MAMP/htdocs/php_oop/autoload.php:22 Stack trace: #0
{main} thrown in /Applications/MAMP/htdocs/php_oop/autoload.php on
line 22
Just to test that require_once does find my aviator.php I tried it out and then commented it out.
What am I doing wrong here?
This code:
<?php
namespace designblob;
function autoloader($class){
include "wrappers/databaseWrapper.php";
}
spl_autoload_register('autoloader');
?>
throws this error:
Fatal error: Uncaught exception 'LogicException' with message 'Function 'autoloader' not found (function 'autoloader' not found or invalid function name)' in /var/www/xxx/library/autoloader.php:8 Stack trace: #0 /var/www/xxx/library/autoloader.php(8): spl_autoload_register('autoloader') #1 /var/www/xxx/library/debug.php(19): require_once('/var/www/xxx...') #2 {main} thrown in /var/www/xxxm/library/autoloader.php on line 8
Why doesn't it work?
spl_autoload_register('designblob\autoloader');