Search code examples
phpphp-mongodb

How to have eclipse resolve php classes in MongoDB\BSON namespace?


After many comes and goes I managed to install the MongoDB Driver for PHP 5.6 and made it work on OSX El Capitan. (The way it worked was using Homebrew)

To start working on a project I created the folder for the project and using Composer installed the required packages I needed. Between theese packages I required mongodb/mongodb which is the recomended mongo php library to use by the php Manual on line and in the driver github page.

The problem I found is that Eclipse is resolving the classes in the \MongoDB\ namespace but not in the \MongoDB\BSON\ namespace. If I check what Composer installed in the vendor folder I am able to see that the \MongoDB\BSON\ classes in fact are missing. On the other hand if I run the program in the PHP included webserver, it executes as expected.

So my question is how can do or what am I missing for Eclipse to find the missing classes. Are they defined somewhere else?

If this is not possible because they are compiled into a binary library and I have no way to resolve them, Is there any way to have Eclipse not showing these particular classes as mistakes?

Example of class that runs ok in the webserver, but is highlighted as an error in Eclipse:

$fecha_creacion  = new MongoDB\BSON\UTCDateTime();

Solution

  • Reading this post and not finding anything newer on the subject I arrived to the conclusion that developers of the driver don't provide the php sources and leave it to the IDE developers to provide STUBs for the different fuctions of the driver in a way the IDE can recognize the functions and provide syntax checking and documentations popups.

    Following this question, I finally ended up finding a JetBrains GitHub where there are many different stubs for PHPStrom, this one among them.

    So I copied the file and added it to my project as part of the sources. And that solved my problem.