php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73746 Method that returns string returns UNKNOWN:0 instead
Submitted: 2016-12-15 08:52 UTC Modified: 2016-12-15 09:39 UTC
From: info at mhlavac dot net Assigned:
Status: Closed Package: opcache
PHP Version: 7.1.0 OS: Ubuntu 16.04
Private report: No CVE-ID:
 [2016-12-15 08:52 UTC] info at mhlavac dot net
Description:
------------
We upgraded to php 7.1 and noticed some tests are failing. This method call returns UNKNOWN:0 since the upgrade. If we remove method return type, then we get expected string that is really returned by the method.

I noticed that this "sometimes" doesn't happen for the first run, so it might be opcache related.

I noticed, removing self::CZ and changing it to CountryMapping::CZ fixes the issue. Also removing return type fixes it as well.

Opcache is enabled. Settings:
opcache.blacklist_filename => no value => no value
opcache.consistency_checks => 0 => 0
opcache.dups_fix => Off => Off
opcache.enable => On => On
opcache.enable_cli => On => On
opcache.enable_file_override => Off => Off
opcache.error_log => no value => no value
opcache.fast_shutdown => 1 => 1
opcache.file_cache => no value => no value
opcache.file_cache_consistency_checks => 1 => 1
opcache.file_cache_only => 0 => 0
opcache.file_update_protection => 2 => 2
opcache.force_restart_timeout => 180 => 180
opcache.huge_code_pages => Off => Off
opcache.inherited_hack => On => On
opcache.interned_strings_buffer => 16 => 16
opcache.lockfile_path => /tmp => /tmp
opcache.log_verbosity_level => 1 => 1
opcache.max_accelerated_files => 65407 => 65407
opcache.max_file_size => 0 => 0
opcache.max_wasted_percentage => 5 => 5
opcache.memory_consumption => 192 => 192
opcache.opt_debug_level => 0 => 0
opcache.optimization_level => 0x7FFFBFFF => 0x7FFFBFFF
opcache.preferred_memory_model => no value => no value
opcache.protect_memory => 0 => 0
opcache.restrict_api => no value => no value
opcache.revalidate_freq => 0 => 0
opcache.revalidate_path => Off => Off
opcache.save_comments => 1 => 1
opcache.use_cwd => On => On
opcache.validate_permission => Off => Off
opcache.validate_root => Off => Off
opcache.validate_timestamps => On => On


Test script:
---------------
<?php
namespace Core\Bundle\Service\Property\Room\Rooms;

class CountryMapping
{
    const CZ = 'CZ';
    const EN = 'EN';

    public function get(string $countryIsoCode = null) : string // Works correctly if return type is removed
    {
        switch (strtoupper($countryIsoCode)) {
            case 'CZ':
            case 'SK':
                return self::CZ; // Works correctly if changed to CountryMapping::CZ
            default:
                return self::EN; // Works correctly if changed to CountryMapping::EN
        }
    }
}

$mapping = new CountryMapping();
var_dump($mapping->get('CZ'));


Expected result:
----------------
string(2) "CZ"

Actual result:
--------------
UNKNOWN:0

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-15 09:39 UTC] yohgaki@php.net
-Package: *General Issues +Package: opcache
 [2016-12-15 09:39 UTC] yohgaki@php.net
It seems this is an opcache issue.

Works without opcache
https://3v4l.org/Ju5dp

PHP crashes with supplied INI on assertion
[yohgaki@dev PHP-7.1]$ cat test.ini
opcache.blacklist_filename=
opcache.consistency_checks=0
opcache.dups_fix=Off
opcache.enable=On
opcache.enable_cli=On
opcache.enable_file_override=Off
opcache.error_log=
opcache.fast_shutdown=1
opcache.file_cache=
opcache.file_cache_consistency_checks=1
opcache.file_cache_only=0
opcache.file_update_protection=2
opcache.force_restart_timeout=180
opcache.huge_code_pages=Off
opcache.inherited_hack=On
opcache.interned_strings_buffer=16
opcache.lockfile_path=/tmp
opcache.log_verbosity_level=1
opcache.max_accelerated_files=65407
opcache.max_file_size=0
opcache.max_wasted_percentage=5
opcache.memory_consumption=192
opcache.opt_debug_level=0
opcache.optimization_level=0x7FFFBFFF
opcache.preferred_memory_model=
opcache.protect_memory=0
opcache.restrict_api=
opcache.revalidate_freq=0
opcache.revalidate_path=Off
opcache.save_comments=1
opcache.use_cwd=On
opcache.validate_permission=Off
opcache.validate_root=Off
opcache.validate_timestamps=On

(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:58
#1  0x00007ffff19b752a in __GI_abort () at abort.c:89
#2  0x00007ffff19ade37 in __assert_fail_base (fmt=<optimized out>, assertion=assertion@entry=0x7fffe671da38 "(opline + 1)->opcode == 62 || (opline + 1)->opcode == 111", 
    file=file@entry=0x7fffe671d460 "/home/yohgaki/git/oss/php.net/PHP-7.1/ext/opcache/Optimizer/zend_optimizer.c", line=line@entry=509, 
    function=function@entry=0x7fffe671de40 <__PRETTY_FUNCTION__.13834> "zend_optimizer_replace_by_const") at assert.c:92
#3  0x00007ffff19adee2 in __GI___assert_fail (assertion=0x7fffe671da38 "(opline + 1)->opcode == 62 || (opline + 1)->opcode == 111", 
    file=0x7fffe671d460 "/home/yohgaki/git/oss/php.net/PHP-7.1/ext/opcache/Optimizer/zend_optimizer.c", line=509, 
    function=0x7fffe671de40 <__PRETTY_FUNCTION__.13834> "zend_optimizer_replace_by_const") at assert.c:101
#4  0x00007fffe66cf0b8 in zend_optimizer_replace_by_const (op_array=0x7fffed402250, opline=0x7fffed48b140, type=2 '\002', var=128, val=0x7fffffff9cd0)
    at /home/yohgaki/git/oss/php.net/PHP-7.1/ext/opcache/Optimizer/zend_optimizer.c:509
#5  0x00007fffe66d217e in zend_optimizer_pass1 (op_array=0x7fffed402250, ctx=0x7fffffff9ec0) at /home/yohgaki/git/oss/php.net/PHP-7.1/ext/opcache/Optimizer/pass1_5.c:353
#6  0x00007fffe66cfbe9 in zend_optimize (op_array=0x7fffed402250, ctx=0x7fffffff9ec0) at /home/yohgaki/git/oss/php.net/PHP-7.1/ext/opcache/Optimizer/zend_optimizer.c:697
#7  0x00007fffe66d01e5 in zend_optimize_op_array (op_array=0x7fffed402250, ctx=0x7fffffff9ec0) at /home/yohgaki/git/oss/php.net/PHP-7.1/ext/opcache/Optimizer/zend_optimizer.c:864
#8  0x00007fffe66d0549 in zend_optimize_script (script=0x7fffed477200, optimization_level=2147467263, debug_level=0)
    at /home/yohgaki/git/oss/php.net/PHP-7.1/ext/opcache/Optimizer/zend_optimizer.c:935
#9  0x00007fffe66aeb6c in cache_script_in_shared_memory (new_persistent_script=0x7fffed477200, key=0x7fffe6933cac <accel_globals+556> "t.p:169112:169192", key_length=17, 
    from_shared_memory=0x7fffffffa0e0) at /home/yohgaki/git/oss/php.net/PHP-7.1/ext/opcache/ZendAccelerator.c:1271
#10 0x00007fffe66b0564 in persistent_compile_file (file_handle=0x7fffffffd720, type=8) at /home/yohgaki/git/oss/php.net/PHP-7.1/ext/opcache/ZendAccelerator.c:1863
#11 0x0000000000abc440 in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /home/yohgaki/git/oss/php.net/PHP-7.1/Zend/zend.c:1468
#12 0x0000000000a2a8fd in php_execute_script (primary_file=0x7fffffffd720) at /home/yohgaki/git/oss/php.net/PHP-7.1/main/main.c:2539
#13 0x0000000000b9c3e1 in do_cli (argc=6, argv=0x154c600) at /home/yohgaki/git/oss/php.net/PHP-7.1/sapi/cli/php_cli.c:990
#14 0x0000000000b9d3ab in main (argc=6, argv=0x154c600) at /home/yohgaki/git/oss/php.net/PHP-7.1/sapi/cli/php_cli.c:1378
 [2016-12-16 03:06 UTC] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7cef66c6352eb6398517fcf3acde128052e0fbd9
Log: Fixed bug #73746 (Method that returns string returns UNKNOWN:0 instead)
 [2016-12-16 03:07 UTC] laruence@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Feb 28 14:01:40 2017 UTC