I'm having issues to suppress a warning that should not come.
The following code produces no output (as expected) when run, but shows an warning on VS Code only when devsense is on.

<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$command = new \MongoDB\Driver\BulkWrite();

I have no other PHP extensions installed.
I'm running VS Code on WSL: Debian.

VSCode PHP Ouput:

PHP extension started.
Found PHP, version: 8.2.5, Xdebug: not loaded.
PHP Language Server Started.

VSCode PHP language server output:

PHP Tools server started.
PID: 6313
Processing files: *.php; *.phtml

Content and run:
leo@MyComp:~$ cat test.php

<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$command = new \MongoDB\Driver\BulkWrite();

leo@MyComp:~$ php test.php

    LeoSubirana Hello, and thank you for submitting the issue.

    Note, ini_set('display_errors', 1); has no effect on the reported code problems.

    Anyways, the error is expected if such a class (class MongoDB\Driver\BulkWrite) is not defined in your opened Folder/Workspace.

    • May I ask, in what file is the class MongoDB\Driver\BulkWrite defined?
    • Do you see that PHP file in your VSCode Explorer?

      No, the class is installed as a PHP extension package from apt on both the production system and my Dev environment
      > php -i
      [...]
      /etc/php/8.2/cli/conf.d/20-mongodb.ini
      [...]

      >cat /etc/php/8.2/cli/conf.d/20-mongodb.ini
      extension=mongodb.so

      The production system is something I have no much control of, so adding a vendor with the libs is not my candidate solution if possible

        6 days later

        Well, it solved it for Manager, Query, BulkWrite and Command, which is really great to get that messages out.

        Still marks as unkown:
        MongoDB\\BSON\\ObjectID and MongoDB\\BSON\\UTCDateTime

        [{
        	"resource": "[...]/util/MongoUtil.php",
        	"owner": "_generated_diagnostic_collection_name_#2",
        	"code": "PHP0413",
        	"severity": 4,
        	"message": "Use of unknown class: 'MongoDB\\BSON\\ObjectID'",
        	"source": "PHP",
        	"startLineNumber": 36,
        	"startColumn": 20,
        	"endLineNumber": 36,
        	"endColumn": 42
        },{
        	"resource": "[...]/util/MongoUtil.php",
        	"owner": "_generated_diagnostic_collection_name_#2",
        	"code": "PHP0413",
        	"severity": 4,
        	"message": "Use of unknown class: 'MongoDB\\BSON\\UTCDateTime'",
        	"source": "PHP",
        	"startLineNumber": 55,
        	"startColumn": 20,
        	"endLineNumber": 55,
        	"endColumn": 45
        }]

        @JakubMisek Sorry to impersonate you even with the thread makred as "solved", maybe you can take a look on my last reply.

          LeoSubirana That's weird, I'm having both classes in both IntelliSense and no problems reported:

          I guess reloading VSCode doesn't help?

            Nope:

            VS Code running over WSL 2 on Debian 11.6.
            Extension: PHP v1.33.12934, DEVSENSE
            VS Code about:

            Version: 1.77.3 (user setup)
            Commit: 704ed70d4fd1c6bd6342c436f1ede30d1cff4710
            Date: 2023-04-12T09:16:02.548Z (3 wks ago)
            Electron: 19.1.11
            Chromium: 102.0.5005.196
            Node.js: 16.14.2
            V8: 10.2.154.26-electron.0
            OS: Windows_NT x64 10.0.19044
            Sandboxed: No

            php -v:

            PHP 8.2.5 (cli) (built: Apr 14 2023 04:39:46) (NTS)
            Copyright (c) The PHP Group
            Zend Engine v4.2.5, Copyright (c) Zend Technologies
            with Zend OPcache v8.2.5, Copyright (c), by Zend Technologies

            php -i | grep mongo:

            MongoDB support => enabled
            MongoDB extension version => 1.15.0
            MongoDB extension stability => stable
            libmongoc bundled version => 1.23.1
            libmongoc SSL => enabled
            libmongoc SSL library => OpenSSL
            libmongoc crypto => enabled
            libmongoc crypto library => libcrypto
            libmongoc crypto system profile => disabled
            libmongoc SASL => enabled
            libmongoc ICU => disabled
            libmongoc compression => enabled
            libmongoc compression snappy => enabled
            libmongoc compression zlib => enabled
            libmongoc compression zstd => enabled
            libmongocrypt bundled version => 1.5.2
            libmongocrypt crypto => enabled
            libmongocrypt crypto library => libcrypto
            mongodb.debug => no value => no value

            LeoSubirana Thanks!

            I've found the bug - fixing and preparing a new pre-release and later today full release.

            edit: workaround for now is to add "bson" to "php.stubs" setting, but it won't be necessary after the update.

            Write a Reply...