Skip to content
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

Replace version_compare on PHP_VERSION with PHP_VERSION_ID check #53

Merged
merged 4 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/zend-db/library/Zend/Db/Adapter/Pdo/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected function _connect()
}

if (!empty($this->_config['charset'])
&& version_compare(PHP_VERSION, '5.3.6', '<')
&& PHP_VERSION_ID < 50306
) {
$initCommand = "SET NAMES '" . $this->_config['charset'] . "'";
$this->_config['driver_options'][1002] = $initCommand; // 1002 = PDO::MYSQL_ATTR_INIT_COMMAND
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static function factory($options = null)

// unfortunately is_subclass_of is broken on some 5.3 versions
// additionally instanceof is also broken for this use case
if (version_compare(PHP_VERSION, '5.3.7', '>=')) {
if (PHP_VERSION_ID >= 50307) {
if (!is_subclass_of($class, 'Zend_Loader_SplAutoloader')) {
// require_once 'Exception/InvalidArgumentException.php';
throw new Zend_Loader_Exception_InvalidArgumentException(sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ protected function loadClass($class, $type)
if ($type === self::ACT_AS_FALLBACK) {
// create filename
$filename = $this->transformClassNameToFilename($class, '');
if (version_compare(PHP_VERSION, '5.3.2', '>=')) {
if (PHP_VERSION_ID >= 50302) {
$resolvedName = stream_resolve_include_path($filename);
if ($resolvedName !== false) {
return include $resolvedName;
Expand Down
4 changes: 2 additions & 2 deletions packages/zend-mobile/library/Zend/Mobile/Push/Apns.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ public function send(Zend_Mobile_Push_Message_Abstract $message)
foreach($message->getCustomData() as $k => $v) {
$payload[$k] = $v;
}
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {

if (PHP_VERSION_ID >= 50400) {
$payload = json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
} else {
$payload = json_encode($payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public function toJson()
if ($this->_ttl !== 2419200) {
$json['time_to_live'] = $this->_ttl;
}
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
if (PHP_VERSION_ID >= 50400) {
return json_encode($json, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
} else {
return json_encode($json);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function call(array $args = array())
{
$callback = $this->getCallback();

$isPhp54 = version_compare(PHP_VERSION, '5.4.0rc1', '>=');
$isPhp54 = PHP_VERSION_ID >= 50400;

if ($isPhp54 && is_string($callback)) {
$this->validateStringCallbackFor54($callback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ protected function _getStackTrace($options)

$spliceOffset = 2;
//Debug backtrace changed in PHP 7.0.0
if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
if (PHP_VERSION_ID >= 70000) {
$spliceOffset = 1;
}
$trace = array_splice($trace, $spliceOffset);
Expand Down
13 changes: 2 additions & 11 deletions packages/zend-xml/library/Zend/Xml/Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,9 @@ public static function scanFile($file, DOMDocument $dom = null)
*/
public static function isPhpFpm()
{
$isVulnerableVersion = (
version_compare(PHP_VERSION, '5.5.22', 'lt')
|| (
version_compare(PHP_VERSION, '5.6', 'ge')
&& version_compare(PHP_VERSION, '5.6.6', 'lt')
)
);
$isVulnerableVersion = PHP_VERSION_ID < 50522 || (PHP_VERSION_ID >= 50600 && PHP_VERSION_ID < 50606);

if (substr(php_sapi_name(), 0, 3) === 'fpm' && $isVulnerableVersion) {
return true;
}
return false;
return $isVulnerableVersion && strpos(php_sapi_name(), 'fpm') === 0;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Zend/Amf/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public function testAmf0MixedArrayParameterDeserializedToNativePhpObject()
// In PHP versions less than 7, get_object_vars doesn't return numerical
// keys. In PHP 7.2+ array_key_exists on this particular object returns false
// https://3v4l.org/ui8Fm
if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
if (PHP_VERSION_ID >= 70000) {
$this->assertTrue(array_key_exists(1, get_object_vars($data[0])));
} else {
$this->assertTrue(array_key_exists(1, $data[0]));
Expand Down
4 changes: 2 additions & 2 deletions tests/Zend/Date/DateObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public function testCalcSunInternal()
// (which was later reverted in php < 7.2.0)
// Example of the difference: https://3v4l.org/v46rk
// Not really something we can test the same in all versions, so doing a version_compare here.
if (version_compare(PHP_VERSION, '7.2.0', '>=')) {
if (PHP_VERSION_ID >= 70200) {
$this->assertSame( 9961716, $date->calcSun(array('latitude' => 38.4, 'longitude' => -29), -0.0145439, true ));
$this->assertSame(10010341, $date->calcSun(array('latitude' => 38.4, 'longitude' => -29), -0.0145439, false));
$this->assertSame( 9966981, $date->calcSun(array('latitude' => -38.4, 'longitude' => -29), -0.0145439, true ));
Expand Down Expand Up @@ -321,7 +321,7 @@ public function testCalcSunInternal()
}

$date = new Zend_Date_DateObjectTestHelper(-148309884);
if (version_compare(PHP_VERSION, '7.2.0', '>=')) {
if (PHP_VERSION_ID >= 70200) {
$this->assertSame(-148322626, $date->calcSun(array('latitude' => 38.4, 'longitude' => -29), -0.0145439, true ));
$this->assertSame(-148274784, $date->calcSun(array('latitude' => 38.4, 'longitude' => -29), -0.0145439, false));
$this->assertSame(-148318143, $date->calcSun(array('latitude' => -38.4, 'longitude' => -29), -0.0145439, true ));
Expand Down
14 changes: 8 additions & 6 deletions tests/Zend/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3821,7 +3821,9 @@ public function testSunFunc()
// PHP's internal sunrise/sunset calculation changed in 7.2.0
// See comment in Zend/Date/DateObjectTest.php::testCalcSunInternal
// This applies to all of the version_compare blocks in this test
if (version_compare(PHP_VERSION, '7.2.0', '>=')) {
$isPhp72 = PHP_VERSION_ID >= 70200;

if ($isPhp72) {
$this->assertSame('2002-01-04T20:09:40+05:00', $result->get(Zend_Date::W3C));
} else {
$this->assertSame('2002-01-04T20:09:59+05:00', $result->get(Zend_Date::W3C));
Expand All @@ -3831,7 +3833,7 @@ public function testSunFunc()
$result = Zend_Date_Cities::City('vienna', 'civil');
$this->assertTrue(is_array($result));
$result = $date->getSunset($result);
if (version_compare(PHP_VERSION, '7.2.0', '>=')) {
if ($isPhp72) {
$this->assertSame('2002-01-04T20:09:01+05:00', $result->get(Zend_Date::W3C));
} else {
$this->assertSame('2002-01-04T20:09:20+05:00', $result->get(Zend_Date::W3C));
Expand All @@ -3841,7 +3843,7 @@ public function testSunFunc()
$result = Zend_Date_Cities::City('vienna', 'nautic');
$this->assertTrue(is_array($result));
$result = $date->getSunset($result);
if (version_compare(PHP_VERSION, '7.2.0', '>=')) {
if ($isPhp72) {
$this->assertSame('2002-01-04T20:08:15+05:00', $result->get(Zend_Date::W3C));
} else {
$this->assertSame('2002-01-04T20:08:34+05:00', $result->get(Zend_Date::W3C));
Expand All @@ -3851,7 +3853,7 @@ public function testSunFunc()
$result = Zend_Date_Cities::City('vienna', 'astronomic');
$this->assertTrue(is_array($result));
$result = $date->getSunset($result);
if (version_compare(PHP_VERSION, '7.2.0', '>=')) {
if ($isPhp72) {
$this->assertSame('2002-01-04T20:07:30+05:00', $result->get(Zend_Date::W3C));
} else {
$this->assertSame('2002-01-04T20:07:49+05:00', $result->get(Zend_Date::W3C));
Expand All @@ -3861,7 +3863,7 @@ public function testSunFunc()
$result = Zend_Date_Cities::City('BERLIN');
$this->assertTrue(is_array($result));
$result = $date->getSunrise($result);
if (version_compare(PHP_VERSION, '7.2.0', '>=')) {
if ($isPhp72) {
$this->assertSame('2002-01-04T12:21:26+05:00', $result->get(Zend_Date::W3C));
} else {
$this->assertSame('2002-01-04T12:21:21+05:00', $result->get(Zend_Date::W3C));
Expand All @@ -3871,7 +3873,7 @@ public function testSunFunc()
$result = Zend_Date_Cities::City('London');
$this->assertTrue(is_array($result));
$result = $date->getSunInfo($result);
if (version_compare(PHP_VERSION, '7.2.0', '>=')) {
if ($isPhp72) {
$this->assertSame('2002-01-04T13:10:15+05:00', $result['sunrise']['effective']->get(Zend_Date::W3C ));
$this->assertSame('2002-01-04T13:10:59+05:00', $result['sunrise']['civil']->get(Zend_Date::W3C ));
$this->assertSame('2002-01-04T13:11:50+05:00', $result['sunrise']['nautic']->get(Zend_Date::W3C ));
Expand Down
4 changes: 2 additions & 2 deletions tests/Zend/Filter/HtmlEntitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function testQuoteStyleQuotesEncodeNone()
*/
public function testCorrectsForEncodingMismatch()
{
if (version_compare(phpversion(), '5.4', '>=')) {
if (PHP_VERSION_ID >= 50400) {
$this->markTestIncomplete('Tested feature ZF-11344 is not available because of PHP bug #63450');
}

Expand All @@ -234,7 +234,7 @@ public function testCorrectsForEncodingMismatch()
*/
public function testStripsUnknownCharactersWhenEncodingMismatchDetected()
{
if (version_compare(phpversion(), '5.4', '>=')) {
if (PHP_VERSION_ID >= 50400) {
$this->markTestIncomplete('Tested feature ZF-11344 is not available because of PHP bug #63450');
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Zend/Ldap/ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function testToLdapSerialize($expect, $convert){
}

public function toLdapSerializeProvider(){
if (getenv('CI') && version_compare(PHP_VERSION, '5.4.0', '>=')) {
if (getenv('CI') && PHP_VERSION_ID >= 50400) {
return array(
array('N;', null),
array('i:1;', 1),
Expand All @@ -121,7 +121,7 @@ public function toLdapSerializeProvider(){
);
}

if (version_compare(PHP_VERSION, '5.6.0beta4', '>=')) {
if (PHP_VERSION_ID >= 50400) {
return array(
array('N;', null),
array('i:1;', 1),
Expand Down
2 changes: 1 addition & 1 deletion tests/Zend/Loader/AutoloaderFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function testRegisteringValidMapFilePopulatesAutoloader()
*/
public function testFactoryCatchesInvalidClasses()
{
if (!version_compare(PHP_VERSION, '5.3.7', '>=')) {
if (PHP_VERSION_ID < 50307) {
$this->markTestSkipped('Cannot test invalid interface loader with versions less than 5.3.7');
}
include dirname(__FILE__) . '/_files/InvalidInterfaceAutoloader.php';
Expand Down
2 changes: 1 addition & 1 deletion tests/Zend/Log/Writer/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function setUp()
*/
public function testSetFormatter()
{
if (version_compare(phpversion(), '7', '>=')) {
if (PHP_VERSION_ID >= 70000) {
$this->markTestSkipped('Invalid typehinting is PHP Fatal error in PHP7+');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Zend/Log/Writer/DbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function testFactory()
*/
public function testThrowStrictSetFormatter()
{
if (version_compare(phpversion(), '7', '>=')) {
if (PHP_VERSION_ID >= 70000) {
$this->markTestSkipped('Invalid typehinting is PHP Fatal error in PHP7+');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Zend/Serializer/Adapter/PhpCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function testUnserializeObject()

public function testUnserialzeInvalid()
{
if (version_compare(phpversion(), '7', '>=')) {
if (PHP_VERSION_ID >= 70000) {
$this->markTestSkipped('Evaling of invalid input is PHP Parse error in PHP7+');
}
$value = 'not a serialized string';
Expand Down
2 changes: 1 addition & 1 deletion tests/Zend/Soap/AllTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function suite()

//early exit because of segfault in this specific version
//https://github.com/zendframework/zf1/issues/650
if (getenv('CI') && version_compare(PHP_VERSION, '5.4.37', '=')) {
if (getenv('CI') && PHP_VERSION_ID >= 50437) {
return $suite;
}

Expand Down