-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose the library version to support deprecations #558
Comments
The
You can contrast these annotations with actual deprecations in
Between If you're use case has nothing to do with transactions, I would suggest sticking with Checking for the availability of new APIs is easily accomplished with We previously considered implementing a version constant in PHPLIB-131 but ultimately decided against it. Rather than rehash the reasons here, I'd encourage you to check the ticket and the related discussion in #280. |
Thanks for the fast and detailed explanation. The needs for 1.2/1.3/1.4 compatibility comes from the fact that the code (the drupal module) needs to work on environments (like macOS X) where version 1.4 cannot be required because it doesn't support the PHP extension versions available in the builtin or Homebrew PHP. So at any given time, the module may have to run on any version at or above 1.2.0 : this has indeed nothing to do with transactions. The problem with maintaining use of count() is that it increases the reported error count in static analysis reports because of the Just read PHPLIB-131 and #280. Thanks for the information. Guess I'll have to use one of the suggested workarounds. FWIW, my current logic is at https://github.com/fgm/mongodb/pull/27/files?utf8=%E2%9C%93&diff=split&w=1#diff-213bffb5b19104d56561eea15854f864R47 |
Extension version 1.5.0 is absolutely supported on macOS. The more general issue is that Homebrew itself removed all formula for PECL extensions when the PHP tap was deprecated a few months ago. We've since updated the install instructions to advise macOS users to instead install the driver with
In the interest of satisfying static analysis, does the tool support any way to disable checks for a segment of code? For example, Scrutinizer CI allows annotations to suppress false positives.
I think that method can be improved with something like: if ( ! empty(static::$libraryVersion)) {
return static::$libraryVersion;
}
if (method_exists(Collection::class, 'countDocuments')) {
return (static::$libraryVersion = '1.4.0');
}
if (method_exists(Collection::class, 'watch')) {
return (static::$libraryVersion = '1.3.0');
}
return (static::$libraryVersion = '1.2.0'); This would remove the overhead of reflection and any doc block parsing. Even without this approach, there should be no reason to parse |
Thanks for this very nice simplification, and the Pecl note. |
Version 1.4.0 introduced a pair of deprecations (
Collection::count()
andChangeStream::CURSOR_NOT_FOUND
), which cause problems in code using the library because compatibility with earlier versions may require non-identical code. For exampleCollection::countDocuments()
andCollection::estimatedDocumentCount()
are two replacement for the deprecatedCollection::count()
depending on the use case, but code that needs to be compatible with both 1.2/1.3 and 1.4 cannot use either with earlier versions of the library since both were introduced in 1.4.0, so code needs to be aware of the actual library version to decide on the API to use.This is usable by hackish means like using reflection on cout() to check the doccomment for
@deprecated
, or other means, but it would be simpler if the code could just use a version constant or API version constant, so I suggest the library starts exposing such a constant.The text was updated successfully, but these errors were encountered: