php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74442 Opcached version produces a nested array
Submitted: 2017-04-14 16:24 UTC Modified: 2017-04-14 16:59 UTC
From: rasmus@php.net Assigned:
Status: Closed Package: opcache
PHP Version: 7.1.5RC1 OS: Linux
Private report: No CVE-ID: None
 [2017-04-14 16:24 UTC] rasmus@php.net
Description:
------------
Without opcache this script prints 4. With opcache, on the first request to this script you get 4 as well. On the 2nd request when you hit the opcached version you get a nested array. Reproducable from cli with:

opcache.enable_cli=1
opcache.file_cache=/var/tmp
opcache.file_cache_only=1

It is fine in 7.0, so it is something we broke in 7.1

Test script:
---------------
<?php
class Schema_Base {
    public function addField($typeclass, array $params = null) {
        $field = new $typeclass($params);
        return $field;
    }
}

class Field_Base {
    public function __construct(array $params = null) {
        if (! is_array($params)) {
            $params = (array) $params;
        }
        call_user_func_array(array($this, 'acceptParams'), $params);
    }
}

class Field_Integer extends Field_Base {
    protected function acceptParams($bytes = 4) {
        echo print_r($bytes, true);
    }
}

try {
    $schema = new Schema_Base;
    $schema->addField('Field_Integer');
} catch (Throwable $ex) {
    echo "CAUGHT EXCEPTION";
    echo (string)$ex;
}


Expected result:
----------------
4

Actual result:
--------------
Array
(
    [0] => Array
 *RECURSION*
)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-14 16:59 UTC] rasmus@php.net
Note that in the constructor if you do

if(is_null($params)) $params = [];

instead of trying to cast null to an array the problem goes away.
 [2017-04-14 20:21 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=2f22dffd1a4535520959943e2e9aec8b2b9b647f
Log: Fixed bug #74442
 [2017-04-14 20:21 UTC] nikic@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC