I'v a singular proble... if I include files in this manner:
<?php
session_start();
session_regenerate_id();
foreach (glob("../class/*.php") as $filename)
{
echo "$filename\n";
include $filename;
}
foreach (glob("../utilities/*.php") as $filename) {
echo "$filename\n";
include $filename;
}
class ECommerce {
private $checker;
private $errorManager;
/**
* ECommerce constructor.
*/
function __construct() {
$this->checker = new Checker();
$this->errorManager = new ErrorManager();
}
the website doesn't work and when I do
$ecommerce = new ECommerce();
it says that
Class 'ErrorManager' not found in path
I thought anything, when I'v thought to try this:
<?php
session_start();
session_regenerate_id();
include "../class/Checker.php";
include "../class/User.php";
include "../utilities/ErrorManager.php";
class ECommerce {
private $checker;
private $errorManager;
/**
* ECommerce constructor.
*/
function __construct() {
$this->checker = new Checker();
$this->errorManager = new ErrorManager();
}
in this manner, it works and anything does what it has to do!
Inside me, the question "why", has made roots and I can't sleep (really).
Why first manner works for all classes except for ErrorManager?
Thank you before!
Here, there is ErrorManager class code (it has the blank construct like Checker class)
<?php
class ErrorManager
{
function __construct() {
}
function getErrorUserNameNotValid() {
return "Nome inserito non valido";
}
function getErrorUserSurnameNotValid() {
return "Cognome inserito non valido";
}
function getErrorUserEmailAlreadyExists() {
return "Email inserita non valida!";
}
function getErrorUserEmailNotValid() {
return "Email inserita non valida!";
}
function getErrorUserPasswordNotValid() {
return "Password inserita non valida! Inserisci una password che sia lunga tra i 6 e i 50 caratteri!";
}
function getErrorUserAddressNotValid() {
return "Indirizzo inserito non valido!";
}
function getErrorUserPhoneNumberNotValid() {
return "Numero telefonico inserito non valido! Inserisci solo numeri, senza trattini o caratteri speciali!";
}
}
I include a screenshot of folder too
I'm trying this now, with AutoLoader:
This is in ECommerce class:
spl_autoload_register('MyAutoloader::ClassLoader');
spl_autoload_register('MyAutoloader::LibraryLoader');
And this is in MyAutoloaderClass
class MyAutoloader
{
public static function ClassLoader($className)
{
$path = "../class/";
include $path.$className.'.php';
}
public static function LibraryLoader($className)
{
$path = __DIR__."/";
include $path.$className.'.php';
}
}
It says that
include(../class/ErrorManager.php): failed to open stream: No such file or directory in