8000 compare version using PHP_VERSION_ID by xabbuh · Pull Request #12497 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

compare version using PHP_VERSION_ID #12497

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

Merged
merged 1 commit into from
Nov 17, 2014
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 autoload.php.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

if (version_compare(PHP_VERSION, '5.4', '>=') && gc_enabled()) {
if (PHP_VERSION_ID >= 50400 && gc_enabled()) {
// Disabling Zend Garbage Collection to prevent segfaults with PHP5.4+
// https://bugs.php.net/bug.php?id=53976
gc_disable();
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Extension/CodeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public function formatFile($file, $line, $text = null)
$text = "$text at line $line";

if (false !== $link = $this->getFileLink($file, $line)) {
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
} else {
$flags = ENT_QUOTES;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testCompile()

protected function getVariableGetter($name)
{
if (version_compare(phpversion(), '5.4.0RC1', '>=')) {
if (PHP_VERSION_ID >= 50400) {
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes()

protected function getVariableGetter($name)
{
if (version_compare(phpversion(), '5.4.0RC1', '>=')) {
if (PHP_VERSION_ID >= 50400) {
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testCompileStrict()
}
protected function getVariableGetterWithoutStrictCheck($name)
{
if (version_compare(phpversion(), '5.4.0RC1', '>=')) {
if (PHP_VERSION_ID >= 50400) {
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
}

Expand All @@ -47,7 +47,7 @@ protected function getVariableGetterWithoutStrictCheck($name)

protected function getVariableGetterWithStrictCheck($name)
{
if (version_compare(phpversion(), '5.4.0RC1', '>=')) {
if (PHP_VERSION_ID >= 50400) {
return sprintf('(isset($context["%s"]) ? $context["%s"] : $this->getContext($context, "%s"))', $name, $name, $name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ServerRunCommand extends ContainerAwareCommand
*/
public function isEnabled()
{
if (version_compare(phpversion(), '5.4.0', '<')) {
if (PHP_VERSION_ID < 50400) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function formatFile($file, $line, $text = null)
}

if (false !== $link = $this->getFileLink($file, $line)) {
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
} else {
$flags = ENT_QUOTES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testRoutingErrorIsNotExposedForProtectedResourceWhenAnonymous($c
*/
public function testRoutingErrorIsExposedWhenNotProtected($config)
{
if (strpos(PHP_OS, "WIN") === 0 && version_compare(phpversion(), "5.3.9", "<")) {
if (defined('PHP_WINDOWS_VERSION_BUILD') && PHP_VERSION_ID < 50309) {
$this->markTestSkipped('Test hangs on Windows & PHP due to https://bugs.php.net/bug.php?id=60120 fixed in http://svn.php.net/viewvc?view=revision&revision=318366');
}

Expand All @@ -46,7 +46,7 @@ public function testRoutingErrorIsExposedWhenNotProtected($config)
*/
public function testRoutingErrorIsNotExposedForProtectedResourceWhenLoggedInWithInsufficientRights($config)
{
if (strpos(PHP_OS, "WIN") === 0 && version_compare(phpversion(), "5.3.9", "<")) {
if (defined('PHP_WINDOWS_VERSION_BUILD') && PHP_VERSION_ID < 50309) {
$this->markTestSkipped('Test hangs on Windows & PHP due to https://bugs.php.net/bug.php?id=60120 fixed in http://svn.php.net/viewvc?view=revision&revision=318366');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/ClassLoader/ClassMapGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Component\ClassLoader;

if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
define('SYMFONY_TRAIT', T_TRAIT);
} else {
define('SYMFONY_TRAIT', 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
{
public function testTraitDependencies()
{
if (version_compare(phpversion(), '5.4', '<')) {
if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('Requires PHP > 5.4');

return;
Expand Down Expand Up @@ -100,7 +100,7 @@ public function getDifferentOrders()
*/
public function testClassWithTraitsReordering(array $classes)
{
if (version_compare(phpversion(), '5.4', '<')) {
if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('Requires PHP > 5.4');

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function getTestCreateMapTests()
)),
);

if (version_compare(PHP_VERSION, '5.4', '>=')) {
if (PHP_VERSION_ID >= 50400) {
$data[] = array(__DIR__.'/Fixtures/php5.4', array(
'TFoo' => __DIR__.'/Fixtures/php5.4/traits.php',
'CFoo' => __DIR__.'/Fixtures/php5.4/traits.php',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ protected function describeApplication(Application $application, array $options
*/
private function formatDefaultValue($default)
{
if (version_compare(PHP_VERSION, '5.4', '<')) {
if (PHP_VERSION_ID < 50400) {
return str_replace('\/', '/', json_encode($default));
}

Expand Down F438
2 changes: 1 addition & 1 deletion src/Symfony/Component/Debug/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function handle($level, $message, $file = 'unknown', $line = 0, $context

if ($level & (E_USER_DEPRECATED | E_DEPRECATED)) {
if (isset(self::$loggers['deprecation'])) {
if (version_compare(PHP_VERSION, '5.4', '<')) {
if (PHP_VERSION_ID < 50400) {
$stack = array_map(
function ($row) {
unset($row['args']);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Debug/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private function abbrClass($class)
*/
private function formatArgs(array $args)
{
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
} else {
$flags = ENT_QUOTES;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/DomCrawler/Crawler.php
10000
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ public function html()

$html = '';
foreach ($this->getNode(0)->childNodes as $child) {
if (version_compare(PHP_VERSION, '5.3.6', '>=')) {
if (PHP_VERSION_ID >= 50306) {
// node parameter was added to the saveHTML() method in PHP 5.3.6
// @see http://php.net/manual/en/domdocument.savehtml.php
$html .= $child->ownerDocument->saveHTML($child);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function __construct($inputTimezone = null, $outputTimezone = null, $form
// The pipe in the parser pattern only works as of PHP 5.3.7
// See http://bugs.php.net/54316
$this->parseUsingPipe = null === $parseUsingPipe
? version_compare(phpversion(), '5.3.7', '>=')
? PHP_VERSION_ID >= 50307
: $parseUsingPipe;

// See http://php.net/manual/en/datetime.createfromformat.php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function isCsrfTokenValid($intention, $token)
*/
protected function getSessionId()
{
if (version_compare(PHP_VERSION, '5.4', '>=')) {
if (PHP_VERSION_ID >= 50400) {
if (PHP_SESSION_NONE === session_status()) {
session_start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function dataProvider()
);

// This test will fail < 5.3.9 - see https://bugs.php.net/51994
if (version_compare(phpversion(), '5.3.9', '>=')) {
if (PHP_VERSION_ID >= 50309) {
$data[] = array('Y-z', '2010-33', '2010-02-03 00:00:00 UTC');
}

Expand Down Expand Up @@ -111,7 +111,7 @@ public function testTransformExpectsDateTime()
*/
public function testReverseTransformUsingPipe($format, $input, $output)
{
if (version_compare(phpversion(), '5.3.7', '<')) {
if (PHP_VERSION_ID < 50307) {
$this->markTestSkipped('Pipe usage requires PHP 5.3.7 or newer.');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function testGenerateCsrfTokenOnUnstartedSession()
{
session_id('touti');

if (!version_compare(PHP_VERSION, '5.4', '>=')) {
if (PHP_VERSION_ID < 50400) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't mean >= ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pborreli no. there was a negation before the version_compare

$this->markTestSkipped('This test requires PHP >= 5.4');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public function send()
while (($level = ob_get_level()) > 0 && $level !== $previous) {
$previous = $level;
if ($obStatus[$level - 1]) {
if (version_compare(PHP_VERSION, '5.4', '>=')) {
if (PHP_VERSION_ID >= 50400) {
if (isset($obStatus[$level - 1]['flags']) && ($obStatus[$level - 1]['flags'] & PHP_OUTPUT_HANDLER_REMOVABLE)) {
ob_end_flush();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @see http://php.net/sessionhandler
*/

if (version_compare(phpversion(), '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
class NativeSessionHandler extends \SessionHandler
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function __construct(array $options = array(), $handler = null, MetadataB
session_cache_limiter(''); // disable by default because it's managed by HeaderBag (if used)
ini_set('session.use_cookies', 1);

if (version_compare(phpversion(), '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
session_register_shutdown();
} else {
register_shutdown_function('session_write_close');
Expand Down Expand Up @@ -130,11 +130,11 @@ public function start()
return true;
}

if (version_compare(phpversion(), '5.4.0', '>=') && \PHP_SESSION_ACTIVE === session_status()) {
if (PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE === session_status()) {
throw new \RuntimeException('Failed to start the session: already started by PHP.');
}

if (version_compare(phpversion(), '5.4.0', '<') && isset($_SESSION) && session_id()) {
if (PHP_VERSION_ID < 50400 && isset($_SESSION) && session_id()) {
// not 100% fool-proof, but is the most reliable way to determine if a session is active in PHP 5.3
throw new \RuntimeException('Failed to start the session: already started by PHP ($_SESSION is set).');
}
Expand Down Expand Up @@ -366,13 +366,13 @@ public function setSaveHandler($saveHandler = null)
if (!$saveHandler instanceof AbstractProxy && $saveHandler instanceof \SessionHandlerInterface) {
$saveHandler = new SessionHandlerProxy($saveHandler);
} elseif (!$saveHandler instanceof AbstractProxy) {
$saveHandler = version_compare(phpversion(), '5.4.0', '>=') ?
$saveHandler = PHP_VERSION_ID >= 50400 ?
new SessionHandlerProxy(new \SessionHandler()) : new NativeProxy();
}
$this->saveHandler = $saveHandler;

if ($this->saveHandler instanceof \SessionHandlerInterface) {
if (version_compare(phpversion(), '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
session_set_save_handler($this->saveHandler, false);
} else {
session_set_save_handler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function isWrapper()
*/
public function isActive()
{
if (version_compare(phpversion(), '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
return $this->active = \PHP_SESSION_ACTIVE === session_status();
}

Expand All @@ -93,7 +93,7 @@ public function isActive()
*/
public function setActive($flag)
{
if (version_compare(phpversion(), '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
throw new \LogicException('This method is disabled in PHP 5.4.0+');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testConstruct()
{
$storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeFileSessionHandler(sys_get_temp_dir()));

if (version_compare(phpversion(), '5.4.0', '<')) {
if (PHP_VERSION_ID < 50400) {
$this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
$this->assertEquals('files', ini_get('session.save_handler'));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testConstruct()

// note for PHPUnit optimisers - the use of assertTrue/False
// here is deliberate since the tests do not require the classes to exist - drak
if (version_compare(phpversion(), '5.4.0', '<')) {
if (PHP_VERSION_ID < 50400) {
$this->assertFalse($handler instanceof \SessionHandler);
$this->assertTrue($handler instanceof NativeSessionHandler);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function testSetSaveHandlerException()

public function testSetSaveHandler53()
{
if (version_compare(phpversion(), '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
$this->markTestSkipped('Test skipped, for PHP 5.3 only.');
}

Expand All @@ -186,7 +186,7 @@ public function testSetSaveHandler53()

public function testSetSaveHandler54()
{
if (version_compare(phpversion(), '5.4.0', '<')) {
if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('Test skipped, for PHP 5.4 only.');
}

Expand All @@ -211,7 +211,7 @@ public function testSetSaveHandler54()
*/
public function testStartedOutside53()
{
if (version_compare(phpversion(), '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
$this->markTestSkipped('Test skipped, for PHP 5.3 only.');
}

Expand All @@ -234,7 +234,7 @@ public function testStartedOutside53()
*/
public function testCanStartOutside54()
{
if (version_compare(phpversion(), '5.4.0', '<')) {
if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('Test skipped, for PHP 5.4 only.');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected function getStorage()

public function testPhpSession53()
{
if (version_compare(phpversion(), '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
$this->markTestSkipped('Test skipped, for PHP 5.3 only.');
}

Expand All @@ -84,7 +84,7 @@ public function testPhpSession53()

public function testPhpSession54()
{
if (version_compare(phpversion(), '5.4.0', '<')) {
if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('Test skipped, for PHP 5.4 only.');
}

Expand Down
Loading
0