|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-12-21 16:40 UTC] matthias dot kuehne at ellerhold dot de
[2016-12-21 20:35 UTC] nikic@php.net
-Status: Open
+Status: Duplicate
[2016-12-21 20:35 UTC] nikic@php.net
[2016-12-22 07:12 UTC] matthias dot kuehne at ellerhold dot de
[2016-12-22 12:22 UTC] matthias dot kuehne at ellerhold dot de
[2016-12-22 12:45 UTC] nikic@php.net
[2016-12-22 14:43 UTC] matthias dot kuehne at ellerhold dot de
[2017-01-23 07:57 UTC] matthias dot kuehne at ellerhold dot de
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 18:00:02 2025 UTC |
Description: ------------ When using a class constant in a case statement and having the return type set to a specific type (e. g. string) unitialized values will be returned. I'm using this version: PHP 7.1.0-2+0~20161206214730.10+jessie~1.gbp2889f0 (cli) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.1.0-2+0~20161206214730.10+jessie~1.gbp2889f0, Copyright (c) 1999-2016, by Zend Technologies with Xdebug v2.5.0, Copyright (c) 2002-2016, by Derick Rethans Same error occurs with PHP 7.1.0-3+0~20161220205825.11+jessie~1.gbpf2e248 (cli) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.1.0-3+0~20161220205825.11+jessie~1.gbpf2e248, Copyright (c) 1999-2016, by Zend Technologies with Xdebug v2.5.0, Copyright (c) 2002-2016, by Derick Rethans From https://deb.sury.org/ . Neither 7.0.14 from sury had this error, nor the 7.0.14 from dotdeb. Test script: --------------- The script can be found here: https://github.com/MatthiasKuehneEllerhold/php71-opcache-failure/blob/master/test.php Posting it here for completeness: <?php namespace Test; class TestClass { const TYPE_V = 'V'; const TYPE_M = 'M'; const NAME_V = 'Very'; const NAME_M = 'Master'; protected $type; public function __construct(string $type) { $this->type = $type; } public function test(): string { switch ($this->type) { case self::TYPE_V: return self::NAME_V; case self::TYPE_M: return self::NAME_M; default: // do nothing break; } return $this->type; } public function testWORKING() { switch ($this->type) { case self::TYPE_V: return self::NAME_V; case self::TYPE_M: return self::NAME_M; default: // do nothing break; } return $this->type; } } // Testcase for PHP 7.1 Opcache failure $class = new TestClass(TestClass::TYPE_M); // This will print out some random bullshit like "boolean true" or the class file path var_dump($class->test()); // This will print out the correct string "Master" var_dump($class->testWORKING()); Expected result: ---------------- The var_dump of $class->test() should display "string 'Master'". Actual result: -------------- I have witnessed these results: * the file path to the class * "*uninitialized*" * boolean true