php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73801 switch-Statement mit Class-Constants lead to uninitialized return
Submitted: 2016-12-21 16:38 UTC Modified: 2016-12-22 12:44 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: matthias dot kuehne at ellerhold dot de Assigned:
Status: Duplicate Package: opcache
PHP Version: 7.1.0 OS: Debian Jessie
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: matthias dot kuehne at ellerhold dot de
New email:
PHP Version: OS:

 

 [2016-12-21 16:38 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-21 16:40 UTC] matthias dot kuehne at ellerhold dot de
P.S.: Disabling the opcache via opcache.enable=0 in the php.ini (and restarting php7.1-fpm) fixes the error.
 [2016-12-21 20:35 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2016-12-21 20:35 UTC] nikic@php.net
This is a duplicate of bug #73789, which will be fixed in PHP 7.1.1 :)
 [2016-12-22 07:12 UTC] matthias dot kuehne at ellerhold dot de
Yeah the descriptions sound similar, didnt find it in my research prior to opening the bug. :(

Thanks and have a nice christmas and new years eve!
 [2016-12-22 12:22 UTC] matthias dot kuehne at ellerhold dot de
More discussion at https://github.com/oerdnj/deb.sury.org/issues/507

Ondrej Sury built a new PHP-version with the fixes from #73789 and I still got the same error. So the patch from #73789 might not be enough.
 [2016-12-22 12:45 UTC] nikic@php.net
Just checked, your test case runs fine under current 7.1 branch. Note that there have been three different fixes regarding handling of return types in opcache, namely:

https://github.com/php/php-src/commit/3b79f8f408ab090825bc15656e517746fdc43db9
https://github.com/php/php-src/commit/60249f439012598717f97ce250f06181116502ea
https://github.com/php/php-src/commit/6bd41a1d47417ad2c7938a57c8abca4e210d5cf6

I did not check it, but it may be that only pulling in the last one does not fix the issue.
 [2016-12-22 14:43 UTC] matthias dot kuehne at ellerhold dot de
Ondrej Sury had missed the middle commit and added it to 7.1.0-5. Its not ready yet and I'll be able to test it after the holidays. Thanks for your effort!
 [2017-01-23 07:57 UTC] matthias dot kuehne at ellerhold dot de
Ok, I can confirm that the error is fixed in PHP 7.1.1-1+0~20170120094658.14+jessie~1.gbp69d416.

Thanks!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Nov 11 20:01:30 2024 UTC