Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feature #22820 Remove PHP < 7.1.3 code (ogizanagi)
This PR was squashed before being merged into the 4.0-dev branch (closes #22820).

Discussion
----------

Remove PHP < 7.1.3 code

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | yes
| Deprecations? | no <!-- don't forget updating UPGRADE-*.md files -->
| Tests pass?   | yes
| Fixed tickets | #22733
| License       | MIT
| Doc PR        | N/A

Commits
-------

7091fb4 Remove PHP < 7.1.3 code
  • Loading branch information
nicolas-grekas committed May 22, 2017
2 parents 619f01c + 7091fb4 commit c09e897
Show file tree
Hide file tree
Showing 69 changed files with 119 additions and 567 deletions.
6 changes: 1 addition & 5 deletions src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php
Expand Up @@ -93,11 +93,7 @@ public function getHtmlCallGraph()
public function getProfile()
{
if (null === $this->profile) {
if (PHP_VERSION_ID >= 70000) {
$this->profile = unserialize($this->data['profile'], array('allowed_classes' => array('Twig_Profiler_Profile')));
} else {
$this->profile = unserialize($this->data['profile']);
}
$this->profile = unserialize($this->data['profile'], array('allowed_classes' => array('Twig_Profiler_Profile')));
}

return $this->profile;
Expand Down
12 changes: 2 additions & 10 deletions src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php
Expand Up @@ -82,11 +82,7 @@ public function testOneVar()
EOTXT;

if (PHP_VERSION_ID >= 70000) {
$expected = preg_replace('/%(.*?)%/', '($context["$1"] ?? null)', $expected);
} else {
$expected = preg_replace('/%(.*?)%/', '(isset($context["$1"]) ? $context["$1"] : null)', $expected);
}
$expected = preg_replace('/%(.*?)%/', '($context["$1"] ?? null)', $expected);

$this->assertSame($expected, $compiler->compile($node)->getSource());
}
Expand All @@ -113,11 +109,7 @@ public function testMultiVars()
EOTXT;

if (PHP_VERSION_ID >= 70000) {
$expected = preg_replace('/%(.*?)%/', '($context["$1"] ?? null)', $expected);
} else {
$expected = preg_replace('/%(.*?)%/', '(isset($context["$1"]) ? $context["$1"] : null)', $expected);
}
$expected = preg_replace('/%(.*?)%/', '($context["$1"] ?? null)', $expected);

$this->assertSame($expected, $compiler->compile($node)->getSource());
}
Expand Down
6 changes: 1 addition & 5 deletions src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php
Expand Up @@ -67,10 +67,6 @@ public function testCompile()

protected function getVariableGetter($name)
{
if (PHP_VERSION_ID >= 70000) {
return sprintf('($context["%s"] ?? null)', $name, $name);
}

return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
return sprintf('($context["%s"] ?? null)', $name, $name);
}
}
Expand Up @@ -264,10 +264,6 @@ public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes()

protected function getVariableGetter($name)
{
if (PHP_VERSION_ID >= 70000) {
return sprintf('($context["%s"] ?? null)', $name, $name);
}

return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
return sprintf('($context["%s"] ?? null)', $name, $name);
}
}
12 changes: 2 additions & 10 deletions src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php
Expand Up @@ -40,11 +40,7 @@ public function testCompileStrict()

protected function getVariableGetterWithoutStrictCheck($name)
{
if (PHP_VERSION_ID >= 70000) {
return sprintf('($context["%s"] ?? null)', $name, $name);
}

return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
return sprintf('($context["%s"] ?? null)', $name, $name);
}

protected function getVariableGetterWithStrictCheck($name)
Expand All @@ -53,10 +49,6 @@ protected function getVariableGetterWithStrictCheck($name)
return sprintf('(isset($context["%s"]) || array_key_exists("%s", $context) ? $context["%s"] : (function () { throw new Twig_Error_Runtime(\'Variable "%s" does not exist.\', 0, $this->getSourceContext()); })())', $name, $name, $name, $name);
}

if (PHP_VERSION_ID >= 70000) {
return sprintf('($context["%s"] ?? $this->getContext($context, "%s"))', $name, $name, $name);
}

return sprintf('(isset($context["%s"]) ? $context["%s"] : $this->getContext($context, "%s"))', $name, $name, $name);
return sprintf('($context["%s"] ?? $this->getContext($context, "%s"))', $name, $name, $name);
}
}
Expand Up @@ -85,10 +85,8 @@ public function extract($resource, MessageCatalogue $catalog)
foreach ($files as $file) {
$this->parseTokens(token_get_all(file_get_contents($file)), $catalog);

if (PHP_VERSION_ID >= 70000) {
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
gc_mem_caches();
}
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
gc_mem_caches();
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php
Expand Up @@ -53,19 +53,17 @@ function ($key, $value, $isHit) {
}

/**
* This adapter should only be used on PHP 7.0+ to take advantage of how PHP
* stores arrays in its latest versions. This factory method decorates the given
* fallback pool with this adapter only if the current PHP version is supported.
* This adapter to take advantage of how PHP stores arrays in its latest versions.
*
* @param string $file The PHP file were values are cached
* @param CacheItemPoolInterface $fallbackPool Fallback for old PHP versions or opcache disabled
* @param CacheItemPoolInterface $fallbackPool Fallback when opcache is disabled
*
* @return CacheItemPoolInterface
*/
public static function create($file, CacheItemPoolInterface $fallbackPool)
{
// Shared memory is available in PHP 7.0+ with OPCache enabled and in HHVM
if ((PHP_VERSION_ID >= 70000 && ini_get('opcache.enable')) || defined('HHVM_VERSION')) {
if (ini_get('opcache.enable') || defined('HHVM_VERSION')) {
if (!$fallbackPool instanceof AdapterInterface) {
$fallbackPool = new ProxyAdapter($fallbackPool);
}
Expand Down
6 changes: 2 additions & 4 deletions src/Symfony/Component/Cache/Simple/PhpArrayCache.php
Expand Up @@ -37,9 +37,7 @@ public function __construct($file, CacheInterface $fallbackPool)
}

/**
* This adapter should only be used on PHP 7.0+ to take advantage of how PHP
* stores arrays in its latest versions. This factory method decorates the given
* fallback pool with this adapter only if the current PHP version is supported.
* This adapter to take advantage of how PHP stores arrays in its latest versions.
*
* @param string $file The PHP file were values are cached
*
Expand All @@ -48,7 +46,7 @@ public function __construct($file, CacheInterface $fallbackPool)
public static function create($file, CacheInterface $fallbackPool)
{
// Shared memory is available in PHP 7.0+ with OPCache enabled and in HHVM
if ((PHP_VERSION_ID >= 70000 && ini_get('opcache.enable')) || defined('HHVM_VERSION')) {
if (ini_get('opcache.enable') || defined('HHVM_VERSION')) {
return new static($file, $fallbackPool);
}

Expand Down
Expand Up @@ -124,12 +124,8 @@ public function provideHashedSignature()
yield array(0, 8, '/** priv docblock */');
yield array(0, 9, 'private $priv = 123;');
yield array(1, 10, '/** pub docblock */');
if (PHP_VERSION_ID >= 50600) {
yield array(1, 11, 'public function pub(...$arg) {}');
}
if (PHP_VERSION_ID >= 70000) {
yield array(1, 11, 'public function pub($arg = null): Foo {}');
}
yield array(1, 11, 'public function pub(...$arg) {}');
yield array(1, 11, 'public function pub($arg = null): Foo {}');
yield array(0, 11, "public function pub(\$arg = null) {\nreturn 123;\n}");
yield array(1, 12, '/** prot docblock */');
yield array(1, 13, 'protected function prot($a = array(123)) {}');
Expand Down
10 changes: 1 addition & 9 deletions src/Symfony/Component/Console/Command/Command.php
Expand Up @@ -286,15 +286,7 @@ public function setCode(callable $code)
if ($code instanceof \Closure) {
$r = new \ReflectionFunction($code);
if (null === $r->getClosureThis()) {
if (PHP_VERSION_ID < 70000) {
// Bug in PHP5: https://bugs.php.net/bug.php?id=64761
// This means that we cannot bind static closures and therefore we must
// ignore any errors here. There is no way to test if the closure is
// bindable.
$code = @\Closure::bind($code, $this);
} else {
$code = \Closure::bind($code, $this);
}
$code = \Closure::bind($code, $this);
}
}

Expand Down
5 changes: 0 additions & 5 deletions src/Symfony/Component/Console/Input/ArgvInput.php
Expand Up @@ -148,11 +148,6 @@ private function parseLongOption($token)

if (false !== $pos = strpos($name, '=')) {
if (0 === strlen($value = substr($name, $pos + 1))) {
// if no value after "=" then substr() returns "" since php7 only, false before
// see http://php.net/manual/fr/migration70.incompatible.php#119151
if (PHP_VERSION_ID < 70000 && false === $value) {
$value = '';
}
array_unshift($this->parsed, $value);
}
$this->addLongOption(substr($name, 0, $pos), $value);
Expand Down
6 changes: 0 additions & 6 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Expand Up @@ -1106,9 +1106,6 @@ public function testConsoleErrorEventIsTriggeredOnCommandNotFound()
$this->assertEquals(1, $tester->getStatusCode());
}

/**
* @requires PHP 7
*/
public function testErrorIsRethrownIfNotHandledByConsoleErrorEvent()
{
$application = new Application();
Expand Down Expand Up @@ -1342,9 +1339,6 @@ protected function getDispatcher($skipCommand = false)
return $dispatcher;
}

/**
* @requires PHP 7
*/
public function testErrorIsRethrownIfNotHandledByConsoleErrorEventWithCatchingEnabled()
{
$application = new Application();
Expand Down
8 changes: 1 addition & 7 deletions src/Symfony/Component/Console/Tests/Command/CommandTest.php
Expand Up @@ -392,13 +392,7 @@ public function testSetCodeWithStaticClosure()
$tester = new CommandTester($command);
$tester->execute(array());

if (PHP_VERSION_ID < 70000) {
// Cannot bind static closures in PHP 5
$this->assertEquals('interact called'.PHP_EOL.'not bound'.PHP_EOL, $tester->getDisplay());
} else {
// Can bind static closures in PHP 7
$this->assertEquals('interact called'.PHP_EOL.'bound'.PHP_EOL, $tester->getDisplay());
}
$this->assertEquals('interact called'.PHP_EOL.'bound'.PHP_EOL, $tester->getDisplay());
}

private static function createClosure()
Expand Down
5 changes: 1 addition & 4 deletions src/Symfony/Component/Debug/DebugClassLoader.php
Expand Up @@ -30,7 +30,6 @@ class DebugClassLoader
private static $final = array();
private static $finalMethods = array();
private static $deprecated = array();
private static $php7Reserved = array('int', 'float', 'bool', 'string', 'true', 'false', 'null');
private static $darwinCache = array('/' => array('/', array()));

/**
Expand Down Expand Up @@ -201,9 +200,7 @@ public function loadClass($class)
}
}

if (in_array(strtolower($refl->getShortName()), self::$php7Reserved)) {
@trigger_error(sprintf('The "%s" class uses the reserved name "%s", it will break on PHP 7 and higher', $name, $refl->getShortName()), E_USER_DEPRECATED);
} elseif (preg_match('#\n \* @deprecated (.*?)\r?\n \*(?: @|/$)#s', $refl->getDocComment(), $notice)) {
if (preg_match('#\n \* @deprecated (.*?)\r?\n \*(?: @|/$)#s', $refl->getDocComment(), $notice)) {
self::$deprecated[$name] = preg_replace('#\s*\r?\n \* +#', ' ', $notice[1]);
} else {
// Don't trigger deprecations for classes in the same vendor
Expand Down
58 changes: 2 additions & 56 deletions src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php
Expand Up @@ -59,29 +59,6 @@ public function testIdempotence()
$this->fail('DebugClassLoader did not register');
}

public function testUnsilencing()
{
if (PHP_VERSION_ID >= 70000) {
$this->markTestSkipped('PHP7 throws exceptions, unsilencing is not required anymore.');
}
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('HHVM is not handled in this test case.');
}

ob_start();

$this->iniSet('log_errors', 0);
$this->iniSet('display_errors', 1);

// See below: this will fail with parse error
// but this should not be @-silenced.
@class_exists(__NAMESPACE__.'\TestingUnsilencing', true);

$output = ob_get_clean();

$this->assertStringMatchesFormat('%aParse error%a', $output);
}

public function testStacking()
{
// the ContextErrorException must not be loaded to test the workaround
Expand Down Expand Up @@ -109,13 +86,8 @@ class ChildTestingStacking extends TestingStacking { function foo($bar) {} }
} catch (\ErrorException $exception) {
// if an exception is thrown, the test passed
$this->assertStringStartsWith(__FILE__, $exception->getFile());
if (PHP_VERSION_ID < 70000) {
$this->assertRegExp('/^Runtime Notice: Declaration/', $exception->getMessage());
$this->assertEquals(E_STRICT, $exception->getSeverity());
} else {
$this->assertRegExp('/^Warning: Declaration/', $exception->getMessage());
$this->assertEquals(E_WARNING, $exception->getSeverity());
}
$this->assertRegExp('/^Warning: Declaration/', $exception->getMessage());
$this->assertEquals(E_WARNING, $exception->getSeverity());
} finally {
restore_error_handler();
restore_exception_handler();
Expand Down Expand Up @@ -243,32 +215,6 @@ class_exists('Symfony\Bridge\Debug\Tests\Fixtures\ExtendsDeprecatedParent', true
$this->assertSame($xError, $lastError);
}

public function testReservedForPhp7()
{
if (PHP_VERSION_ID >= 70000) {
$this->markTestSkipped('PHP7 already prevents using reserved names.');
}

set_error_handler(function () { return false; });
$e = error_reporting(0);
trigger_error('', E_USER_NOTICE);

class_exists('Test\\'.__NAMESPACE__.'\\Float', true);

error_reporting($e);
restore_error_handler();

$lastError = error_get_last();
unset($lastError['file'], $lastError['line']);

$xError = array(
'type' => E_USER_DEPRECATED,
'message' => 'The "Test\Symfony\Component\Debug\Tests\Float" class uses the reserved name "Float", it will break on PHP 7 and higher',
);

$this->assertSame($xError, $lastError);
}

public function testExtendedFinalClass()
{
set_error_handler(function () { return false; });
Expand Down
3 changes: 0 additions & 3 deletions src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php
Expand Up @@ -475,9 +475,6 @@ public function testHandleFatalError()
}
}

/**
* @requires PHP 7
*/
public function testHandleErrorException()
{
$exception = new \Error("Class 'Foo' not found");
Expand Down
Expand Up @@ -138,9 +138,6 @@ public function testPrevious(\Exception $exception, $statusCode)
$this->assertSame(array($flattened2), $flattened->getAllPrevious());
}

/**
* @requires PHP 7.0
*/
public function testPreviousError()
{
$exception = new \Exception('test', 123, new \ParseError('Oh noes!', 42));
Expand Down
Expand Up @@ -65,11 +65,7 @@ public function serialize()

public function unserialize($serialized)
{
if (PHP_VERSION_ID >= 70000) {
list($this->class, $this->filePath, $this->autowiringMetadata) = unserialize($serialized, array('allowed_classes' => false));
} else {
list($this->class, $this->filePath, $this->autowiringMetadata) = unserialize($serialized);
}
list($this->class, $this->filePath, $this->autowiringMetadata) = unserialize($serialized, array('allowed_classes' => false));
}

/**
Expand Down
13 changes: 6 additions & 7 deletions src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Expand Up @@ -1409,13 +1409,14 @@ private function dumpValue($value, $interpolate = true)
$value = $value->getValues()[0];
$code = $this->dumpValue($value, $interpolate);

$returnedType = '';
if ($value instanceof TypedReference) {
$code = sprintf('$f = function (\\%s $v%s) { return $v; }; return $f(%s);', $value->getType(), ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $value->getInvalidBehavior() ? ' = null' : '', $code);
} else {
$code = sprintf('return %s;', $code);
$returnedType = sprintf(': %s\%s', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE === $value->getInvalidBehavior() ? '' : '?', $value->getType());
}

return sprintf("function () {\n %s\n }", $code);
$code = sprintf('return %s;', $code);

return sprintf("function ()%s {\n %s\n }", $returnedType, $code);
}

if ($value instanceof IteratorArgument) {
Expand Down Expand Up @@ -1628,9 +1629,7 @@ private function getServiceCall($id, Reference $reference = null)
}

if ($this->container->hasDefinition($id) && (!$this->container->getDefinition($id)->isPublic() || $this->container->getDefinition($id)->isShared())) {
// The following is PHP 5.5 syntax for what could be written as "(\$this->services['$id'] ?? $code)" on PHP>=7.0

$code = "\${(\$_ = isset(\$this->services['$id']) ? \$this->services['$id'] : $code) && false ?: '_'}";
$code = "(\$this->services['$id'] ?? $code)";
}

return $code;
Expand Down
Expand Up @@ -49,10 +49,6 @@ public static function getSignature(\ReflectionFunctionAbstract $r, &$call = nul
$k = substr($k, 1);
}
} catch (\ReflectionException $e) {
if ($type && $p->allowsNull() && !class_exists('ReflectionNamedType', false)) {
$k .= ' = null';
$k = substr($k, 1);
}
}

$signature[] = $k;
Expand Down

0 comments on commit c09e897

Please sign in to comment.