Skip to content

Commit 367ed3c

Browse files
committed
compare version using PHP_VERSION_ID
To let opcode caches optimize cached code, the `PHP_VERSION_ID` constant is used to detect the current PHP version instead of calling `version_compare()` with `PHP_VERSION`.
1 parent 8d18c98 commit 367ed3c

File tree

44 files changed

+85
-100
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+85
-100
lines changed

autoload.php.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
if (version_compare(PHP_VERSION, '5.4', '>=') && gc_enabled()) {
3+
if (PHP_VERSION_ID >= 50400 && gc_enabled()) {
44
// Disabling Zend Garbage Collection to prevent segfaults with PHP5.4+
55
// https://bugs.php.net/bug.php?id=53976
66
gc_disable();

src/Symfony/Bridge/Twig/Extension/CodeExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public function formatFile($file, $line, $text = null)
172172
$text = "$text at line $line";
173173

174174
if (false !== $link = $this->getFileLink($file, $line)) {
175-
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
175+
if (PHP_VERSION_ID >= 50400) {
176176
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
177177
} else {
178178
$flags = ENT_QUOTES;

src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function testCompile()
6767

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

src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes()
264264

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

src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function testCompileStrict()
3838
}
3939
protected function getVariableGetterWithoutStrictCheck($name)
4040
{
41-
if (version_compare(phpversion(), '5.4.0RC1', '>=')) {
41+
if (PHP_VERSION_ID >= 50400) {
4242
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
4343
}
4444

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

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

src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ServerRunCommand extends ContainerAwareCommand
2929
*/
3030
public function isEnabled()
3131
{
32-
if (version_compare(phpversion(), '5.4.0', '<')) {
32+
if (PHP_VERSION_ID < 50400) {
3333
return false;
3434
}
3535

src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function formatFile($file, $line, $text = null)
166166
}
167167

168168
if (false !== $link = $this->getFileLink($file, $line)) {
169-
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
169+
if (PHP_VERSION_ID >= 50400) {
170170
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
171171
} else {
172172
$flags = ENT_QUOTES;

src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testRoutingErrorIsNotExposedForProtectedResourceWhenAnonymous($c
3030
*/
3131
public function testRoutingErrorIsExposedWhenNotProtected($config)
3232
{
33-
if (strpos(PHP_OS, "WIN") === 0 && version_compare(phpversion(), "5.3.9", "<")) {
33+
if (defined('PHP_WINDOWS_VERSION_BUILD') && PHP_VERSION_ID < 50309) {
3434
$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');
3535
}
3636

@@ -46,7 +46,7 @@ public function testRoutingErrorIsExposedWhenNotProtected($config)
4646
*/
4747
public function testRoutingErrorIsNotExposedForProtectedResourceWhenLoggedInWithInsufficientRights($config)
4848
{
49-
if (strpos(PHP_OS, "WIN") === 0 && version_compare(phpversion(), "5.3.9", "<")) {
49+
if (defined('PHP_WINDOWS_VERSION_BUILD') && PHP_VERSION_ID < 50309) {
5050
$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');
5151
}
5252

src/Symfony/Component/ClassLoader/ClassMapGenerator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Component\ClassLoader;
1313

14-
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
14+
if (PHP_VERSION_ID >= 50400) {
1515
define('SYMFONY_TRAIT', T_TRAIT);
1616
} else {
1717
define('SYMFONY_TRAIT', 0);

src/Symfony/Component/ClassLoader/Tests/ClassCollectionLoaderTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
2222
{
2323
public function testTraitDependencies()
2424
{
25-
if (version_compare(phpversion(), '5.4', '<')) {
25+
if (PHP_VERSION_ID < 50400) {
2626
$this->markTestSkipped('Requires PHP > 5.4');
2727

2828
return;
@@ -100,7 +100,7 @@ public function getDifferentOrders()
100100
*/
101101
public function testClassWithTraitsReordering(array $classes)
102102
{
103-
if (version_compare(phpversion(), '5.4', '<')) {
103+
if (PHP_VERSION_ID < 50400) {
104104
$this->markTestSkipped('Requires PHP > 5.4');
105105

106106
return;

src/Symfony/Component/ClassLoader/Tests/ClassMapGeneratorTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function getTestCreateMapTests()
104104
)),
105105
);
106106

107-
if (version_compare(PHP_VERSION, '5.4', '>=')) {
107+
if (PHP_VERSION_ID >= 50400) {
108108
$data[] = array(__DIR__.'/Fixtures/php5.4', array(
109109
'TFoo' => __DIR__.'/Fixtures/php5.4/traits.php',
110110
'CFoo' => __DIR__.'/Fixtures/php5.4/traits.php',

src/Symfony/Component/Console/Descriptor/TextDescriptor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ protected function describeApplication(Application $application, array $options
186186
*/
187187
private function formatDefaultValue($default)
188188
{
189-
if (version_compare(PHP_VERSION, '5.4', '<')) {
189+
if (PHP_VERSION_ID < 50400) {
190190
return str_replace('\/', '/', json_encode($default));
191191
}
192192

src/Symfony/Component/Debug/ErrorHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function handle($level, $message, $file = 'unknown', $line = 0, $context
101101

102102
if ($level & (E_USER_DEPRECATED | E_DEPRECATED)) {
103103
if (isset(self::$loggers['deprecation'])) {
104-
if (version_compare(PHP_VERSION, '5.4', '<')) {
104+
if (PHP_VERSION_ID < 50400) {
105105
$stack = array_map(
106106
function ($row) {
107107
unset($row['args']);

src/Symfony/Component/Debug/ExceptionHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ private function abbrClass($class)
288288
*/
289289
private function formatArgs(array $args)
290290
{
291-
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
291+
if (PHP_VERSION_ID >= 50400) {
292292
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
293293
} else {
294294
$flags = ENT_QUOTES;

src/Symfony/Component/DomCrawler/Crawler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ public function html()
530530

531531
$html = '';
532532
foreach ($this->getNode(0)->childNodes as $child) {
533-
if (version_compare(PHP_VERSION, '5.3.6', '>=')) {
533+
if (PHP_VERSION_ID >= 50306) {
534534
// node parameter was added to the saveHTML() method in PHP 5.3.6
535535
// @see http://php.net/manual/en/domdocument.savehtml.php
536536
$html .= $child->ownerDocument->saveHTML($child);

src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function __construct($inputTimezone = null, $outputTimezone = null, $form
6969
// The pipe in the parser pattern only works as of PHP 5.3.7
7070
// See http://bugs.php.net/54316
7171
$this->parseUsingPipe = null === $parseUsingPipe
72-
? version_compare(phpversion(), '5.3.7', '>=')
72+
? PHP_VERSION_ID >= 50307
7373
: $parseUsingPipe;
7474

7575
// See http://php.net/manual/en/datetime.createfromformat.php

src/Symfony/Component/Form/Extension/Csrf/CsrfProvider/DefaultCsrfProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function isCsrfTokenValid($intention, $token)
6565
*/
6666
protected function getSessionId()
6767
{
68-
if (version_compare(PHP_VERSION, '5.4', '>=')) {
68+
if (PHP_VERSION_ID >= 50400) {
6969
if (PHP_SESSION_NONE === session_status()) {
7070
session_start();
7171
}

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function dataProvider()
6060
);
6161

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

@@ -111,7 +111,7 @@ public function testTransformExpectsDateTime()
111111
*/
112112
public function testReverseTransformUsingPipe($format, $input, $output)
113113
{
114-
if (version_compare(phpversion(), '5.3.7', '<')) {
114+
if (PHP_VERSION_ID < 50307) {
115115
$this->markTestSkipped('Pipe usage requires PHP 5.3.7 or newer.');
116116
}
117117

src/Symfony/Component/Form/Tests/Extension/Csrf/CsrfProvider/DefaultCsrfProviderTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function testGenerateCsrfTokenOnUnstartedSession()
4949
{
5050
session_id('touti');
5151

52-
if (!version_compare(PHP_VERSION, '5.4', '>=')) {
52+
if (PHP_VERSION_ID < 50400) {
5353
$this->markTestSkipped('This test requires PHP >= 5.4');
5454
}
5555

src/Symfony/Component/HttpFoundation/Response.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public function send()
324324
while (($level = ob_get_level()) > 0 && $level !== $previous) {
325325
$previous = $level;
326326
if ($obStatus[$level - 1]) {
327-
if (version_compare(PHP_VERSION, '5.4', '>=')) {
327+
if (PHP_VERSION_ID >= 50400) {
328328
if (isset($obStatus[$level - 1]['flags']) && ($obStatus[$level - 1]['flags'] & PHP_OUTPUT_HANDLER_REMOVABLE)) {
329329
ob_end_flush();
330330
}

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NativeSessionHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* @see http://php.net/sessionhandler
1818
*/
1919

20-
if (version_compare(phpversion(), '5.4.0', '>=')) {
20+
if (PHP_VERSION_ID >= 50400) {
2121
class NativeSessionHandler extends \SessionHandler
2222
{
2323
}

src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function __construct(array $options = array(), $handler = null, MetadataB
100100
session_cache_limiter(''); // disable by default because it's managed by HeaderBag (if used)
101101
ini_set('session.use_cookies', 1);
102102

103-
if (version_compare(phpversion(), '5.4.0', '>=')) {
103+
if (PHP_VERSION_ID >= 50400) {
104104
session_register_shutdown();
105105
} else {
106106
register_shutdown_function('session_write_close');
@@ -130,11 +130,11 @@ public function start()
130130
return true;
131131
}
132132

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

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

374374
if ($this->saveHandler instanceof \SessionHandlerInterface) {
375-
if (version_compare(phpversion(), '5.4.0', '>=')) {
375+
if (PHP_VERSION_ID >= 50400) {
376376
session_set_save_handler($this->saveHandler, false);
377377
} else {
378378
session_set_save_handler(

src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/AbstractProxy.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function isWrapper()
7272
*/
7373
public function isActive()
7474
{
75-
if (version_compare(phpversion(), '5.4.0', '>=')) {
75+
if (PHP_VERSION_ID >= 50400) {
7676
return $this->active = \PHP_SESSION_ACTIVE === session_status();
7777
}
7878

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

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testConstruct()
2727
{
2828
$storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeFileSessionHandler(sys_get_temp_dir()));
2929

30-
if (version_compare(phpversion(), '5.4.0', '<')) {
30+
if (PHP_VERSION_ID < 50400) {
3131
$this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
3232
$this->assertEquals('files', ini_get('session.save_handler'));
3333
} else {

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/NativeSessionHandlerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testConstruct()
2828

2929
// note for PHPUnit optimisers - the use of assertTrue/False
3030
// here is deliberate since the tests do not require the classes to exist - drak
31-
if (version_compare(phpversion(), '5.4.0', '<')) {
31+
if (PHP_VERSION_ID < 50400) {
3232
$this->assertFalse($handler instanceof \SessionHandler);
3333
$this->assertTrue($handler instanceof NativeSessionHandler);
3434
} else {

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function testSetSaveHandlerException()
164164

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

@@ -186,7 +186,7 @@ public function testSetSaveHandler53()
186186

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

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

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

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/PhpBridgeSessionStorageTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected function getStorage()
6060

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

@@ -84,7 +84,7 @@ public function testPhpSession53()
8484

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

0 commit comments

Comments
 (0)