From 49fd0efb12434655c60f317d6757b65dfddbbe88 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 23 May 2020 11:54:14 +0200 Subject: [PATCH 1/4] [Cache] Accessing undefined constants raises an Error in php8 --- .../Cache/Tests/Adapter/MemcachedAdapterTest.php | 10 ++++++++-- .../Cache/Tests/Simple/MemcachedCacheTest.php | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php index 3a996079ad..8fe807f880 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php @@ -66,8 +66,14 @@ class MemcachedAdapterTest extends AdapterTestCase */ public function testBadOptions($name, $value) { - $this->expectException('ErrorException'); - $this->expectExceptionMessage('constant(): Couldn\'t find constant Memcached::'); + if (\PHP_VERSION_ID < 80000) { + $this->expectException('ErrorException'); + $this->expectExceptionMessage('constant(): Couldn\'t find constant Memcached::'); + } else { + $this->expectException('Error'); + $this->expectExceptionMessage('Undefined class constant \'Memcached::'); + } + MemcachedAdapter::createConnection([], [$name => $value]); } diff --git a/src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTest.php b/src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTest.php index 21332232bc..92fc7d2a87 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTest.php @@ -76,8 +76,14 @@ class MemcachedCacheTest extends CacheTestCase */ public function testBadOptions($name, $value) { - $this->expectException('ErrorException'); - $this->expectExceptionMessage('constant(): Couldn\'t find constant Memcached::'); + if (\PHP_VERSION_ID < 80000) { + $this->expectException('ErrorException'); + $this->expectExceptionMessage('constant(): Couldn\'t find constant Memcached::'); + } else { + $this->expectException('Error'); + $this->expectExceptionMessage('Undefined class constant \'Memcached::'); + } + MemcachedCache::createConnection([], [$name => $value]); } From 08084f370dd78c7f2673a906b1e2eab25008624f Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Fri, 22 May 2020 22:42:37 +0200 Subject: [PATCH 2/4] Add php 8 to travis. --- .travis.yml | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4251d2fa02..c066f308a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,11 @@ matrix: env: deps=high - php: 7.4 env: deps=low + - php: nightly + services: [memcached] fast_finish: true + allow_failures: + - php: nightly cache: directories: @@ -54,9 +58,11 @@ before_install: - | # Start Redis cluster - docker pull grokzen/redis-cluster:4.0.8 - docker run -d -p 7000:7000 -p 7001:7001 -p 7002:7002 -p 7003:7003 -p 7004:7004 -p 7005:7005 --name redis-cluster grokzen/redis-cluster:4.0.8 - export REDIS_CLUSTER_HOSTS='localhost:7000 localhost:7001 localhost:7002 localhost:7003 localhost:7004 localhost:7005' + if [[ $TRAVIS_PHP_VERSION != nightly ]]; then + docker pull grokzen/redis-cluster:4.0.8 + docker run -d -p 7000:7000 -p 7001:7001 -p 7002:7002 -p 7003:7003 -p 7004:7004 -p 7005:7005 --name redis-cluster grokzen/redis-cluster:4.0.8 + export REDIS_CLUSTER_HOSTS='localhost:7000 localhost:7001 localhost:7002 localhost:7003 localhost:7004 localhost:7005' + fi - | # General configuration @@ -157,11 +163,14 @@ before_install: echo opcache.enable_cli = 1 >> $INI echo hhvm.jit = 0 >> $INI echo apc.enable_cli = 1 >> $INI - echo extension = redis.so >> $INI - echo extension = memcached.so >> $INI if [[ $PHP = 5.* ]]; then + echo extension = redis.so >> $INI + echo extension = memcached.so >> $INI echo extension = memcache.so >> $INI echo extension = mongo.so >> $INI + elif [[ $PHP = 7.* ]]; then + echo extension = redis.so >> $INI + echo extension = memcached.so >> $INI fi done @@ -183,6 +192,8 @@ before_install: elif [[ $PHP = 7.* ]]; then tfold ext.apcu tpecl apcu-5.1.17 apcu.so $INI tfold ext.mongodb tpecl mongodb-1.6.0 mongodb.so $INI + elif [[ $PHP = nightly ]]; then + tfold ext.memcached tpecl memcached-3.1.5 memcached.so $INI fi done @@ -249,6 +260,13 @@ install: export COMPONENTS=$(find src/Symfony -mindepth 3 -type f -name phpunit.xml.dist -not -wholename '*/Bridge/PhpUnit/*' -printf '%h\n' | sort) fi + - | + # Set composer's platform to php 7.4 if we're on php 8. + echo $PHP + if [[ $PHP = nightly ]]; then + composer config platform.php 7.4.6 + fi + - | # Install symfony/flex if [[ $deps = low ]]; then From 9bc1ab62cf6338735d15067c7f08b1ca54aa6570 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 23 May 2020 13:22:31 +0200 Subject: [PATCH 3/4] [VarDumper] fix PHP 8 support --- .../Component/VarDumper/Caster/Caster.php | 20 ++++++++++++++++--- .../Component/VarDumper/Caster/SplCaster.php | 16 ++++----------- .../VarDumper/Cloner/AbstractCloner.php | 7 +++---- .../VarDumper/Tests/Caster/CasterTest.php | 2 +- .../VarDumper/Tests/Caster/PdoCasterTest.php | 3 ++- .../Tests/Caster/ReflectionCasterTest.php | 4 ++-- .../VarDumper/Tests/Caster/SplCasterTest.php | 18 +++++++++++------ .../VarDumper/Tests/Dumper/CliDumperTest.php | 1 + 8 files changed, 42 insertions(+), 29 deletions(-) diff --git a/src/Symfony/Component/VarDumper/Caster/Caster.php b/src/Symfony/Component/VarDumper/Caster/Caster.php index c279249a4d..a78410f2f7 100644 --- a/src/Symfony/Component/VarDumper/Caster/Caster.php +++ b/src/Symfony/Component/VarDumper/Caster/Caster.php @@ -46,7 +46,7 @@ class Caster * * @return array The array-cast of the object, with prefixed dynamic properties */ - public static function castObject($obj, $class, $hasDebugInfo = false) + public static function castObject($obj, $class, $hasDebugInfo = false, $debugClass = null) { if ($class instanceof \ReflectionClass) { @trigger_error(sprintf('Passing a ReflectionClass to "%s()" is deprecated since Symfony 3.3 and will be unsupported in 4.0. Pass the class name as string instead.', __METHOD__), E_USER_DEPRECATED); @@ -71,6 +71,17 @@ class Caster if ($a) { static $publicProperties = []; + if (null === $debugClass) { + if (\PHP_VERSION_ID >= 80000) { + $debugClass = get_debug_type($obj); + } else { + $debugClass = $class; + + if (isset($debugClass[15]) && "\0" === $debugClass[15]) { + $debugClass = (get_parent_class($debugClass) ?: key(class_implements($debugClass)) ?: 'class').'@anonymous'; + } + } + } $i = 0; $prefixedKeys = []; @@ -84,8 +95,8 @@ class Caster if (!isset($publicProperties[$class][$k])) { $prefixedKeys[$i] = self::PREFIX_DYNAMIC.$k; } - } elseif (isset($k[16]) && "\0" === $k[16] && 0 === strpos($k, "\0class@anonymous\0")) { - $prefixedKeys[$i] = "\0".get_parent_class($class).'@anonymous'.strrchr($k, "\0"); + } elseif ($debugClass !== $class && 1 === strpos($k, $class)) { + $prefixedKeys[$i] = "\0".$debugClass.strrchr($k, "\0"); } ++$i; } @@ -101,6 +112,9 @@ class Caster if ($hasDebugInfo && \is_array($debugInfo)) { foreach ($debugInfo as $k => $v) { if (!isset($k[0]) || "\0" !== $k[0]) { + if (\array_key_exists(self::PREFIX_DYNAMIC.$k, $a)) { + continue; + } $k = self::PREFIX_VIRTUAL.$k; } diff --git a/src/Symfony/Component/VarDumper/Caster/SplCaster.php b/src/Symfony/Component/VarDumper/Caster/SplCaster.php index b557b689d3..53df3de239 100644 --- a/src/Symfony/Component/VarDumper/Caster/SplCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/SplCaster.php @@ -160,15 +160,6 @@ class SplCaster return $a; } - public static function castFixedArray(\SplFixedArray $c, array $a, Stub $stub, $isNested) - { - $a += [ - Caster::PREFIX_VIRTUAL.'storage' => $c->toArray(), - ]; - - return $a; - } - public static function castObjectStorage(\SplObjectStorage $c, array $a, Stub $stub, $isNested) { $storage = []; @@ -200,14 +191,16 @@ class SplCaster private static function castSplArray($c, array $a, Stub $stub, $isNested) { $prefix = Caster::PREFIX_VIRTUAL; - $class = $stub->class; $flags = $c->getFlags(); if (!($flags & \ArrayObject::STD_PROP_LIST)) { $c->setFlags(\ArrayObject::STD_PROP_LIST); - $a = Caster::castObject($c, $class); + $a = Caster::castObject($c, \get_class($c), method_exists($c, '__debugInfo'), $stub->class); $c->setFlags($flags); } + if (\PHP_VERSION_ID < 70400) { + $a[$prefix.'storage'] = $c->getArrayCopy(); + } $a += [ $prefix.'flag::STD_PROP_LIST' => (bool) ($flags & \ArrayObject::STD_PROP_LIST), $prefix.'flag::ARRAY_AS_PROPS' => (bool) ($flags & \ArrayObject::ARRAY_AS_PROPS), @@ -215,7 +208,6 @@ class SplCaster if ($c instanceof \ArrayObject) { $a[$prefix.'iteratorClass'] = new ClassStub($c->getIteratorClass()); } - $a[$prefix.'storage'] = $c->getArrayCopy(); return $a; } diff --git a/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php b/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php index aed1a67a1e..f424cc4866 100644 --- a/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php +++ b/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php @@ -102,7 +102,6 @@ abstract class AbstractCloner implements ClonerInterface 'SplDoublyLinkedList' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castDoublyLinkedList'], 'SplFileInfo' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castFileInfo'], 'SplFileObject' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castFileObject'], - 'SplFixedArray' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castFixedArray'], 'SplHeap' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castHeap'], 'SplObjectStorage' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castObjectStorage'], 'SplPriorityQueue' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castHeap'], @@ -266,8 +265,8 @@ abstract class AbstractCloner implements ClonerInterface $obj = $stub->value; $class = $stub->class; - if (isset($class[15]) && "\0" === $class[15] && 0 === strpos($class, "class@anonymous\x00")) { - $stub->class = get_parent_class($class).'@anonymous'; + if ((\PHP_VERSION_ID >= 80000 || (isset($class[15]) && "\0" === $class[15])) && false !== strpos($class, "@anonymous\0")) { + $stub->class = \PHP_VERSION_ID < 80000 ? (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous' : get_debug_type($obj); } if (isset($this->classInfo[$class])) { list($i, $parents, $hasDebugInfo) = $this->classInfo[$class]; @@ -289,7 +288,7 @@ abstract class AbstractCloner implements ClonerInterface $this->classInfo[$class] = [$i, $parents, $hasDebugInfo]; } - $a = Caster::castObject($obj, $class, $hasDebugInfo); + $a = Caster::castObject($obj, $class, $hasDebugInfo, $stub->class); try { while ($i--) { diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/CasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/CasterTest.php index 728697b413..73800e5f9d 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/CasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/CasterTest.php @@ -171,7 +171,7 @@ EOTXT $this->assertDumpMatchesFormat( <<<'EOTXT' -@anonymous { +class@anonymous { -foo: "foo" } EOTXT diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/PdoCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/PdoCasterTest.php index 19bbe0f80c..fca242cfc6 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/PdoCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/PdoCasterTest.php @@ -30,6 +30,7 @@ class PdoCasterTest extends TestCase { $pdo = new \PDO('sqlite::memory:'); $pdo->setAttribute(\PDO::ATTR_STATEMENT_CLASS, ['PDOStatement', [$pdo]]); + $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $cast = PdoCaster::castPdo($pdo, [], new Stub(), false); @@ -45,7 +46,7 @@ array:2 [ "\x00~\x00inTransaction" => false "\x00~\x00attributes" => array:9 [ "CASE" => NATURAL - "ERRMODE" => SILENT + "ERRMODE" => EXCEPTION "PERSISTENT" => false "DRIVER_NAME" => "sqlite" "ORACLE_NULLS" => NATURAL diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php index a0c6dc2355..17ad5434be 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php @@ -49,8 +49,8 @@ ReflectionClass { %A] methods: array:%d [ %A - "export" => ReflectionMethod { - +name: "export" + "__construct" => ReflectionMethod { + +name: "__construct" +class: "ReflectionClass" %A parameters: { $%s: ReflectionParameter { diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/SplCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/SplCasterTest.php index 67033df091..a8c37faf3f 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/SplCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/SplCasterTest.php @@ -175,14 +175,17 @@ EOTXT; $expected = << 123 + ] flag::STD_PROP_LIST: false flag::ARRAY_AS_PROPS: false iteratorClass: "ArrayIterator" - storage: array:1 [ - 0 => 123 - ] } EOTXT; + if (\PHP_VERSION_ID < 70400) { + $expected = str_replace('-storage:', 'storage:', $expected); + } $this->assertDumpEquals($expected, $var); } @@ -196,13 +199,16 @@ EOTXT; $expected = << 234 ] + flag::STD_PROP_LIST: false + flag::ARRAY_AS_PROPS: false } EOTXT; + if (\PHP_VERSION_ID < 70400) { + $expected = str_replace('-storage:', 'storage:', $expected); + } $this->assertDumpEquals($expected, $var); } diff --git a/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php b/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php index 9520b4fe10..7656e09259 100644 --- a/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php @@ -203,6 +203,7 @@ EOTXT; /** * @requires extension xml + * @requires PHP < 8.0 */ public function testXmlResource() { From 232725243bd8be0828bb4a522d954f9a884cd632 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 23 May 2020 14:14:15 +0200 Subject: [PATCH 4/4] Run PHP 8 as 7.4.99 --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c066f308a1..61445ec192 100644 --- a/.travis.yml +++ b/.travis.yml @@ -262,9 +262,8 @@ install: - | # Set composer's platform to php 7.4 if we're on php 8. - echo $PHP if [[ $PHP = nightly ]]; then - composer config platform.php 7.4.6 + composer config platform.php 7.4.99 fi - |