diff --git a/composer.json b/composer.json index 6f7e50ce1..20d8ca7d3 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "forum": "https://groups.google.com/forum/#!forum/twig-users" }, "require": { - "php": ">=5.2.4" + "php": ">=5.2.7" }, "autoload": { "psr-0" : { diff --git a/lib/Twig/Autoloader.php b/lib/Twig/Autoloader.php index 36b10951c..87f741538 100644 --- a/lib/Twig/Autoloader.php +++ b/lib/Twig/Autoloader.php @@ -23,10 +23,10 @@ class Twig_Autoloader */ public static function register($prepend = false) { - if (version_compare(phpversion(), '5.3.0', '>=')) { - spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend); - } else { + if (PHP_VERSION_ID < 50300) { spl_autoload_register(array(__CLASS__, 'autoload')); + } else { + spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend); } } diff --git a/lib/Twig/Error.php b/lib/Twig/Error.php index afb8ddde0..90650c5fe 100644 --- a/lib/Twig/Error.php +++ b/lib/Twig/Error.php @@ -57,7 +57,7 @@ class Twig_Error extends Exception */ public function __construct($message, $lineno = -1, $filename = null, Exception $previous = null) { - if (version_compare(PHP_VERSION, '5.3.0', '<')) { + if (PHP_VERSION_ID < 50300) { $this->previous = $previous; parent::__construct(''); } else { @@ -188,7 +188,7 @@ class Twig_Error extends Exception $template = null; $templateClass = null; - if (version_compare(phpversion(), '5.3.6', '>=')) { + if (PHP_VERSION_ID >= 50306) { $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); } else { $backtrace = debug_backtrace(); diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 4dbee873c..92feea5e7 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -617,7 +617,7 @@ function twig_urlencode_filter($url) return rawurlencode($url); } -if (version_compare(PHP_VERSION, '5.3.0', '<')) { +if (PHP_VERSION_ID < 50300) { /** * JSON encodes a variable. * @@ -1073,9 +1073,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', return $string; case 'url': - // hackish test to avoid version_compare that is much slower, this works unless PHP releases a 5.10.* - // at that point however PHP 5.2.* support can be removed - if (PHP_VERSION < '5.3.0') { + if (PHP_VERSION_ID < 50300) { return str_replace('%7E', '~', rawurlencode($string)); } diff --git a/lib/Twig/Node/Expression/Name.php b/lib/Twig/Node/Expression/Name.php index 4cbdea975..0bfcdbc45 100644 --- a/lib/Twig/Node/Expression/Name.php +++ b/lib/Twig/Node/Expression/Name.php @@ -46,7 +46,7 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression // remove the non-PHP 5.4 version when PHP 5.3 support is dropped // as the non-optimized version is just a workaround for slow ternary operator // when the context has a lot of variables - if (version_compare(phpversion(), '5.4.0RC1', '>=')) { + if (PHP_VERSION_ID >= 50400) { // PHP 5.4 ternary operator performance was optimized $compiler ->raw('(isset($context[') diff --git a/lib/Twig/NodeVisitor/Optimizer.php b/lib/Twig/NodeVisitor/Optimizer.php index 6b4233b53..b9f9a5bfa 100644 --- a/lib/Twig/NodeVisitor/Optimizer.php +++ b/lib/Twig/NodeVisitor/Optimizer.php @@ -56,7 +56,7 @@ class Twig_NodeVisitor_Optimizer implements Twig_NodeVisitorInterface $this->enterOptimizeFor($node, $env); } - if (!version_compare(phpversion(), '5.4.0RC1', '>=') && self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('sandbox')) { + if (PHP_VERSION_ID < 50400 && self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('sandbox')) { if ($this->inABody) { if (!$node instanceof Twig_Node_Expression) { if (get_class($node) !== 'Twig_Node') { diff --git a/lib/Twig/Test/NodeTestCase.php b/lib/Twig/Test/NodeTestCase.php index 9eb44614f..bf865211b 100644 --- a/lib/Twig/Test/NodeTestCase.php +++ b/lib/Twig/Test/NodeTestCase.php @@ -42,7 +42,7 @@ abstract class Twig_Test_NodeTestCase extends PHPUnit_Framework_TestCase { $line = $line > 0 ? "// line {$line}\n" : ''; - if (version_compare(phpversion(), '5.4.0RC1', '>=')) { + if (PHP_VERSION_ID >= 50400) { return sprintf('%s(isset($context["%s"]) ? $context["%s"] : null)', $line, $name, $name); } diff --git a/test/Twig/Tests/Node/Expression/FilterTest.php b/test/Twig/Tests/Node/Expression/FilterTest.php index 2b85141cd..4aefa7e55 100644 --- a/test/Twig/Tests/Node/Expression/FilterTest.php +++ b/test/Twig/Tests/Node/Expression/FilterTest.php @@ -64,7 +64,7 @@ class Twig_Tests_Node_Expression_FilterTest extends Twig_Test_NodeTestCase $tests[] = array($node, 'twig_reverse_filter($this->env, "abc", true)'); // filter as an anonymous function - if (version_compare(phpversion(), '5.3.0', '>=')) { + if (PHP_VERSION_ID >= 50300) { $node = $this->createFilter(new Twig_Node_Expression_Constant('foo', 1), 'anonymous'); $tests[] = array($node, 'call_user_func_array($this->env->getFilter(\'anonymous\')->getCallable(), array("foo"))'); } @@ -112,7 +112,7 @@ class Twig_Tests_Node_Expression_FilterTest extends Twig_Test_NodeTestCase protected function getEnvironment() { - if (version_compare(phpversion(), '5.3.0', '>=')) { + if (PHP_VERSION_ID >= 50300) { return include 'PHP53/FilterInclude.php'; } diff --git a/test/Twig/Tests/Node/Expression/FunctionTest.php b/test/Twig/Tests/Node/Expression/FunctionTest.php index 4d4a72192..209b8cf83 100644 --- a/test/Twig/Tests/Node/Expression/FunctionTest.php +++ b/test/Twig/Tests/Node/Expression/FunctionTest.php @@ -63,7 +63,7 @@ class Twig_Tests_Node_Expression_FunctionTest extends Twig_Test_NodeTestCase $tests[] = array($node, 'twig_date_converter($this->env, 0, "America/Chicago")'); // function as an anonymous function - if (version_compare(phpversion(), '5.3.0', '>=')) { + if (PHP_VERSION_ID >= 50300) { $node = $this->createFunction('anonymous', array(new Twig_Node_Expression_Constant('foo', 1))); $tests[] = array($node, 'call_user_func_array($this->env->getFunction(\'anonymous\')->getCallable(), array("foo"))'); } @@ -78,7 +78,7 @@ class Twig_Tests_Node_Expression_FunctionTest extends Twig_Test_NodeTestCase protected function getEnvironment() { - if (version_compare(phpversion(), '5.3.0', '>=')) { + if (PHP_VERSION_ID >= 50300) { return include 'PHP53/FunctionInclude.php'; } diff --git a/test/Twig/Tests/Node/Expression/NameTest.php b/test/Twig/Tests/Node/Expression/NameTest.php index d013affad..905d8ee9b 100644 --- a/test/Twig/Tests/Node/Expression/NameTest.php +++ b/test/Twig/Tests/Node/Expression/NameTest.php @@ -28,7 +28,7 @@ class Twig_Tests_Node_Expression_NameTest extends Twig_Test_NodeTestCase $env1 = new Twig_Environment(null, array('strict_variables' => false)); return array( - array($node, "// line 1\n".(version_compare(PHP_VERSION, '5.4.0') >= 0 ? '(isset($context["foo"]) ? $context["foo"] : $this->getContext($context, "foo"))' : '$this->getContext($context, "foo")'), $env), + array($node, "// line 1\n".(PHP_VERSION_ID >= 50400 ? '(isset($context["foo"]) ? $context["foo"] : $this->getContext($context, "foo"))' : '$this->getContext($context, "foo")'), $env), array($node, $this->getVariableGetter('foo', 1), $env1), array($self, "// line 1\n\$this"), array($context, "// line 1\n\$context"), diff --git a/test/Twig/Tests/Node/Expression/TestTest.php b/test/Twig/Tests/Node/Expression/TestTest.php index 2f54a5a2e..e62a8afdd 100644 --- a/test/Twig/Tests/Node/Expression/TestTest.php +++ b/test/Twig/Tests/Node/Expression/TestTest.php @@ -32,7 +32,7 @@ class Twig_Tests_Node_Expression_TestTest extends Twig_Test_NodeTestCase $tests[] = array($node, '(null === "foo")'); // test as an anonymous function - if (version_compare(phpversion(), '5.3.0', '>=')) { + if (PHP_VERSION_ID >= 50300) { $node = $this->createTest(new Twig_Node_Expression_Constant('foo', 1), 'anonymous', array(new Twig_Node_Expression_Constant('foo', 1))); $tests[] = array($node, 'call_user_func_array($this->env->getTest(\'anonymous\')->getCallable(), array("foo", "foo"))'); } @@ -47,7 +47,7 @@ class Twig_Tests_Node_Expression_TestTest extends Twig_Test_NodeTestCase protected function getEnvironment() { - if (version_compare(phpversion(), '5.3.0', '>=')) { + if (PHP_VERSION_ID >= 50300) { return include 'PHP53/TestInclude.php'; } diff --git a/test/Twig/Tests/NodeVisitor/OptimizerTest.php b/test/Twig/Tests/NodeVisitor/OptimizerTest.php index 72c777c1e..f79104b8a 100644 --- a/test/Twig/Tests/NodeVisitor/OptimizerTest.php +++ b/test/Twig/Tests/NodeVisitor/OptimizerTest.php @@ -36,7 +36,7 @@ class Twig_Tests_NodeVisitor_OptimizerTest extends PHPUnit_Framework_TestCase public function testRenderVariableBlockOptimizer() { - if (version_compare(phpversion(), '5.4.0RC1', '>=')) { + if (PHP_VERSION_ID >= 50400) { return; }