ZF-35: ZF Version check (TRAC#22)

Issue Type: Improvement Created: 2006-06-19T23:02:27.000+0000 Last Updated: 2007-07-05T14:43:07.000+0000 Status: Resolved Fix version(s): - 0.7.0 (18/Jan/07)

Reporter: Zend Framework (zend_framework) Assignee: Gavin (gavin) Tags: - Zend_Loader

Related issues: Attachments:


sometimes it is a must to check, what ZF version is running, where your applications shares one ZF installation ..

it would be nice, to have a method, where you can check the installed ZF version against a required version,

e.g. if ZendVersion::check("0.3.15") then output "need at least ZF 0.3.15" -- die();

<pre class="highlight">
    class ZendVersion
        static $version = "0.1.13";
        function check($version, $strict = false)
            list($main, $major, $minor) = explode(".", $version);
            list($zf_main, $zf_major, $zf_minor) = explode(".", ZendVersion::$version);
            if (!$strict) {
                return ($minor*10+$major*1000+$main*10000) <= ($zf_minor*10+$zf_major*1000+$zf_main*10000); 
            } else {
                return ($minor*10+$major*1000+$main*10000) == ($zf_minor*10+$zf_major*1000+$zf_main*10000);

simple test

<pre class="highlight">
    $tests = array();
    $tests["0.1.12"] = true;
    $tests["0.1.13"] = true;
    $tests["0.1.14"] = false;
    $tests["1.1.14"] = false;
    echo "ZF version " . ZendVersion::$version . "\n";
    foreach ($tests as $key=>$value)
        echo "checking for '" . $key . "' ";
        if ($value == true)
            echo "true .. ? ";
        } else
            echo "false .. ? ";
        if ($value == ZendVersion::check($key))
            echo "OK";
        } else
            echo "FAILED";
        echo "\n";

test output

<pre class="highlight">
ZF version 0.1.13
checking for '0.1.12' true .. ? OK
checking for '0.1.13' true .. ? OK
checking for '0.1.14' false .. ? OK
checking for '1.1.14' false .. ? OK


Posted by Bill Karwin (bkarwin) on 2006-11-13T15:13:46.000+0000

Changing fix version to 0.6.0.

Posted by Bill Karwin (bkarwin) on 2007-01-16T13:29:22.000+0000

Here are some thoughts:

  • This class should be Zend_Version; the file Version.php should live under the Zend directory.
  • This class should be final; there is no reason to subclass it.
  • check() method should not assume version strings are in NN.NN.NN format. It's possible that version strings may be more complex. I suggest splitting on any non-alphanumeric character into an array, not three scalars.
  • Need method isEqual($version, $strict = false)
  • Need method isGreaterThan($version)
  • Need method isLessThan($version)

Posted by Bill Karwin (bkarwin) on 2007-01-16T13:31:00.000+0000

Reformat code in description to be less wide.

Posted by Gavin (gavin) on 2007-01-17T15:40:31.000+0000

Hmmm .. I have a different, simpler approach, requiring less code. If anyone objects, please let me know asap. See the Fisheye link for the changeset and patch.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.