ZF-9443: Zend_Version, can I please extend it?

Description

As some of the legacy projects I work on slowly adopt ZF, we also adopt some of ZF's conventions (naming, unit testing).

One thing I find common to all projects is tracking the current version. Sometimes I make a file version.text, but I like the way ZF handles it, with the Zend_Version class.

Would it make sense to let me extend that for use in my other projects (so I don't duplicate the compareVersion method?).

I'd suggest to remove the "final class" and convert it to late static binding, just in case.

Comments

Since ZF 1.10 still supports PHP 5.2, late static binding isn't an option. Still an option for ZF2.

Could adjust the compare to

public static function compareVersion($version, $version2 = Zend_Version::VERSION)

to allow for BC, and still use the compare version for items outside of ZF.

The essence of Zend_Version boils down to two things:

  • A constant (Zend_Version::VERSION)
  • The compareVersion() method

compareVersion() is really simply a wrapper for PHP's version_compare, though it contains some minor logic to accommodate what we termed "Preview Release" versions prior to 1.8, but which were, in fact, alpha versions. (The logic does a simple regular expression to translate "pr" to "a" in the version string.) If we did not have those versions haunting us, we would have no need for the method, to be honest.

As long as your version numbers follow those that version_compare() understands, I really see no need to extend Zend_Version; simply create a namespace-level constant or a class constant, and feed it to version_compare().

We may revisit the "final" declaration for 2.0, but likely not prior to that.

If you guys don't intend to add additional business logic to that namespace in the future, then I guess we'd have no use for it.

I can add a method isLastest() to complete the method getLatest().