Classes in include path not accessible (php)

In a PHP-project (IntelliJ+PHP-plugin) I am trying to use a class from an include path. The include path and its content are listed in the Exernal Library section and I have added it as described here.

IntelliJ itself tells me to include that class in the following form (header of my php class that tries to use the included class later):

<?php

namespace php_libraries\models;

use php_libraries\common\MStr;

When I hover over the path listed after "use", the correct location on my hard drive is shown (the include path). I can also Ctrl+click on the included class and it is opened as expected.

However, when I run the project, I always get a fatal error that that MStr class was not found:

Fatal error: Uncaught Error: Class 'php_libraries\common\MStr' not found in [...]\IdeaProjects\php_weather_models\src\php_libraries\models\WeatherModelData.php:266
Stack trace:
#0 {main}
thrown in [...]\php_weather_models\src\php_libraries\models\WeatherModelData.php on line 266

Yes, certainly is it not found in that location, because it is located in the include path. I have tried various things by now (require etc), but, nothing has worked so far.

As I am new to using PHP in IntelliJ, I am probably missing something important.

2 comments
Comment actions Permalink

Hi there,

How do you load your classes? If you are using Composer for that, make sure that you have an entry for `php_libraries` there.

IDE (be it IntelliJ or PhpStorm) does not autoload anything for you. The "Include Paths" settings in IDE is just to tell where it may find your extra classes that are not part of the actual project (3rd party libs) for indexing/navigation purposes.

IDE just tells PHP to run your code.. and the rest is done by PHP. So it's you who is responsible for loading your classes (by using some autoloder (e.g. Composer) or by using include/require statements).

 

P.S. Just in case if you are new to PHP: the "use php_libraries\common\MStr;" line does not mean that the class will be loaded here; It just tells what class is "imported" for full class name resolution purposes, that's it.

1
Comment actions Permalink

Hi Andriy,

thank you for your advice! I did not know those things and have now installed composer. I will try to get it to work and see how that goes.

Mick

0

Please sign in to leave a comment.