Bug #73801 [NEW]: switch-Statement mit Class-Constants lead to uninitialized return

From: Date: Wed, 21 Dec 2016 16:38:29 +0000
Subject: Bug #73801 [NEW]: switch-Statement mit Class-Constants lead to uninitialized return
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-206177@lists.php.net to get a copy of this message
From:             matthias dot kuehne at ellerhold dot de
Operating system: Debian Jessie
PHP version:      7.1.0
Package:          opcache
Bug Type:         Bug
Bug description:switch-Statement mit Class-Constants lead to uninitialized return

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 bug report at https://bugs.php.net/bug.php?id=73801&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=73801&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=73801&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=73801&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=73801&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=73801&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=73801&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=73801&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=73801&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=73801&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=73801&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=73801&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=73801&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=73801&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73801&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=73801&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=73801&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=73801&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73801&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=73801&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=73801&r=mysqlcfg



Thread (7 messages)

« previous php.bugs (#206177) next »