#23060 [Opn]: bad logic in php4/pear/PEAR/Dependency.php

From: Date: Sat, 05 Apr 2003 11:22:56 +0000
Subject: #23060 [Opn]: bad logic in php4/pear/PEAR/Dependency.php
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-14911@lists.php.net to get a copy of this message
ID: 23060 Updated by: jmcastagnetto@php.net Reported By: jmcastagnetto@php.net Status: Open Bug Type: PEAR related Operating System: Red Hat Linux 8.0 PHP Version: 4CVS-2003-04-05 (stable) New Comment: Seems like there is also a similar logic problem in checkZend(). Below is patch for both: $ diff -u php4/pear/PEAR/Dependency.php-orig php4/pear/PEAR/Dependency.php --- php4/pear/PEAR/Dependency.php-orig 2003-04-05 02:43:29.000000000 -0800 +++ php4/pear/PEAR/Dependency.php 2003-04-05 03:20:27.000000000 -0800 @@ -199,14 +199,15 @@ */ function checkPHP(&$errmsg, $req, $relation = 'ge') { - if (substr($relation, 0, 2) == 'v.') { - $php_ver = phpversion(); - $operator = substr($relation, 2); - if (!version_compare("$php_ver", "$req", $operator)) { - $errmsg = "PHP version " . $this->signOperator($operator) . - " $req is required"; - return PEAR_DEPENDENCY_CONFLICT; - } + if (substr($req, 0, 2) == 'v.') { + $req = substr($req,2, strlen($req) - 2); + } + $php_ver = phpversion(); + $operator = substr($relation,0,2); + if (!version_compare("$php_ver", "$req", $operator)) { + $errmsg = "PHP version " . $this->signOperator($operator) . + " $req is required"; + return PEAR_DEPENDENCY_CONFLICT; } return false; } @@ -271,14 +272,15 @@ */ function checkZend(&$errmsg, $req, $relation = 'ge') { - if (substr($relation, 0, 2) == 'v.') { - $zend_ver = zend_version(); - $operator = substr($relation, 2); - if (!version_compare("$zend_ver", "$req", $operator)) { - $errmsg = "Zend version " . $this->signOperator($operator) . - " $req is required"; - return PEAR_DEPENDENCY_CONFLICT; - } + if (substr($req, 0, 2) == 'v.') { + $req = substr($req,2, strlen($req) - 2); + } + $zend_ver = zend_version(); + $operator = substr($relation,0,2); + if (!version_compare("$zend_ver", "$req", $operator)) { + $errmsg = "Zend version " . $this->signOperator($operator) . + " $req is required"; + return PEAR_DEPENDENCY_CONFLICT; } return false; } Previous Comments: ------------------------------------------------------------------------ [2003-04-05 04:45:23] jmcastagnetto@php.net I think there is a logic problem in php4/pear/PEAR/Dependency.php The method "checkPHP()" was checking things incorrectly. According to the package.dtd (and the code earlier in the 'Dependency' class), that method gets passed the 'version' and 'rel' attributes of the 'dep' element, e.g.: <dep type="php" rel="ge" version="4.3"/> but for some reason there was a mix up in the logic of the method's body. The "diff -u" output with fixed logic is below: $ diff -u Dependency.php-orig Dependency.php --- Dependency.php-orig 2003-04-05 02:43:29.000000000 -0800 +++ Dependency.php 2003-04-05 02:45:11.000000000 -0800 @@ -199,14 +199,15 @@ */ function checkPHP(&$errmsg, $req, $relation = 'ge') { - if (substr($relation, 0, 2) == 'v.') { - $php_ver = phpversion(); - $operator = substr($relation, 2); - if (!version_compare("$php_ver", "$req", $operator)) { - $errmsg = "PHP version " . $this->signOperator($operator) . - " $req is required"; - return PEAR_DEPENDENCY_CONFLICT; - } + if (substr($req, 0, 2) == 'v.') { + $req = substr($req,2); + } + $php_ver = phpversion(); + $operator = substr($relation,0,2); + if (!version_compare("$php_ver", "$req", $operator)) { + $errmsg = "PHP version " . $this->signOperator($operator) . + " $req is required"; + return PEAR_DEPENDENCY_CONFLICT; } return false; } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=23060&edit=1

« previous php.pear.dev (#14911) next »