Bug #73801 [Com]: switch-Statement mit Class-Constants lead to uninitialized return
Edit report at https://bugs.php.net/bug.php?id=73801&edit=1
ID: 73801
Comment by: matthias dot kuehne at ellerhold dot de
Reported by: matthias dot kuehne at ellerhold dot de
Summary: switch-Statement mit Class-Constants lead to
uninitialized return
Status: Open
Type: Bug
Package: opcache
Operating System: Debian Jessie
PHP Version: 7.1.0
Block user comment: N
Private report: N
New Comment:
P.S.: Disabling the opcache via opcache.enable=0 in the php.ini (and restarting php7.1-fpm) fixes
the error.
Previous Comments:
------------------------------------------------------------------------
[2016-12-21 16:38:24] matthias dot kuehne at ellerhold dot de
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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73801&edit=1
Thread (7 messages)