mongodb / mongo-php-library

The Official MongoDB PHP library

Home Page:https://mongodb.com/docs/php-library/current/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

get_debug_type() only available for PHP 8.0 and up

stronk7 opened this issue · comments

Bug Report

Was performing some static analysis of codebase here (Moodle), when it detected that the get_debug_type() function is being used in a couple of Exceptions (InvalidArgumentException and ResumeTokenException).

FILE: /cache/stores/mongodb/MongoDB/Exception/InvalidArgumentException.php
----------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------
 59 | ERROR | The function get_debug_type() is not present in PHP version 7.4 or earlier
----------------------------------------------------------------------------------------------------------


FILE: /cache/stores/mongodb/MongoDB/Exception/ResumeTokenException.php
------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------
 33 | ERROR | The function get_debug_type() is not present in PHP version 7.4 or earlier
------------------------------------------------------------------------------------------------------

And that function was new with PHP 8.0, not being available in previous versions. https://3v4l.org/ptSpA

I've looked to code to see if you were overriding/replacing it in some way but, apparently you're not. Our tests and normal use haven't detected any problem, but I imagine that's just because we aren't getting those exceptions ever.

Have searched in issues and PRs here, also in forums, to see if there was any reference about the affair. But haven't found anything, hence, reporting here.

Environment

This potentially affects any PHP 7.x installation of the library, so far. Any OS.

Right now we are using 1.8.0 (see MDL-70309), but the same applies to other, newer, releases.

$ php -i | grep -E 'mongodb|libmongoc|libbson'
/opt/local/var/db/php80/mongodb.ini,
mongodb
libbson headers version => 1.21.0
libbson library version => 1.21.1
libmongoc headers version => 1.21.0
libmongoc library version => 1.21.1
libmongoc SSL => enabled
libmongoc SSL library => Secure Transport
libmongoc crypto => enabled
libmongoc crypto library => Common Crypto
libmongoc crypto system profile => disabled
libmongoc SASL => enabled
libmongoc ICU => enabled
libmongoc compression => enabled
libmongoc compression snappy => enabled
libmongoc compression zlib => enabled
libmongoc compression zstd => enabled
libmongocrypt => disabled
mongodb.debug => no value => no value
mongodb.mock_service_id => Off => Off

Test Script

Sorry, we haven't faced any real problem, just the static analysis (PHPCompatibility) detected it. And seems legit.

Expected and Actual Behavior

N/A

Debug Log

N/A

Thanks for the report. I traced this change back to 78e3606 and that commit references PHPLIB-588, which talks about relying on symfony/polyfill to provide get_debug_type() on older PHP versions. The aformentioned commit also added symfony/polyfill-php80 to composer.json, so I reckon this is a false positive from the static analysis tool.

Aha, didn't look for composer new dependencies, that explains it. Thanks!

OT: Curiously we aren't using that symfony/polyfill-php80 in our library import, that's something we'll have to fix. Good to know.