0

Example:

namespace MyApp\Api;

use Mautic\Auth\AuthInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

/**
* Base API class
*/

class Api implements LoggerAwareInterface
{
//do Api stuff here

If I upload this to my hosting, I am getting "Class Not found" exception. But i I do simple update:

namespace MyApp\Api;

use Mautic\Auth\AuthInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

/**
* Base API class
*/
require_once('Psr/Log/LoggerAwareInterface.php');
require_once('Psr/Log/LoggerInterface.php');
require_once('Psr/Log/NullLogger.php');
class Api implements LoggerAwareInterface
{
 //do stuff

Adding keywords require_once solves the problem and it seems that everything is usable.

Now, some of the packages I use in my PHP projects are done by someone else. So I hate the idea of changing files of someone else. Now, what should I check or change on my hosting?

Basic info of my hosting:

 -- Webserver Configuration

 PHP Version:              5.3.29
 MySQL Version:            5.5.5
 Webserver Info:           Apache

Whad do I have to change on my hosting so the files work on themselves without need to add require keywords?

EDIT I am still bit newbie in PHP programming, so I am using only Notepad++ to develop and usual FTP tool to upload files on my hosting

Stephan
  • 41,764
  • 65
  • 238
  • 329
Pavel Janicek
  • 14,128
  • 14
  • 53
  • 77
  • 4
    Create an autoloader – John Conde Mar 25 '16 at 14:59
  • Can you make it into more detailed, newbie friendly answer? – Pavel Janicek Mar 25 '16 at 15:01
  • aren't you using composer to install the packages? can't you use his autoloader? – Federkun Mar 25 '16 at 15:02
  • I just stupidly downloaded the files and try to use them @Federico – Pavel Janicek Mar 25 '16 at 15:02
  • Then you need a psr-0/4 autoloader. If you don't want use what composer provide you, you can implement [your own](http://www.php-fig.org/psr/psr-4/examples/) or use some library like [this](http://symfony.com/doc/current/components/class_loader/introduction.html). – Federkun Mar 25 '16 at 15:06
  • 3
    1) `use` is just name aliasing, it does not load files. That's why. 2) Start using [Composer](http://getcomposer.org), that's the easiest solution here. – deceze Mar 25 '16 at 15:06

0 Answers0