php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59538 include_once_override = 1 and class redeclaration errors
Submitted: 2010-12-13 18:58 UTC Modified: 2016-10-05 12:50 UTC
From: narsimham at ning dot com Assigned: cmb (profile)
Status: Wont fix Package: APC (PECL)
PHP Version: 5.2.6 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-12-13 18:58 UTC] narsimham at ning dot com
Description:
------------
Hello,

At my work we?re having an issue with APC 3.1.4 and require_once, and after testing we noticed the same problem occur with APC 3.1.6. We?ve come up with some APC patch code to fix it but I don?t think it should be necessary and I doubt that it?s something we would want to commit.

A synopsis:

We are using the PHP Reader project ( http://code.google.com/p/php-reader/ ) and APC 3.1.6 with include_once_override = 1.

In the same request we often include several files from the PHP Reader. These files in turn require_once other files from PHP Reader. Some files are included multiple times per request.

The first time the request goes through there?s nothing in the cache and everything works fine. Apc_cache_info() now tells us that the PHP Reader files are in the cache.

The second time through the exact same request we get PHP Fatal Errors that we cannot redeclare a PHP Reader class ,even though every instance of the class being included in the code is by require_once. (In particular, the error always refers to files that have been require_once?d multiple times during the request; we can make it refer  to various classes by changing up the request data.)

There?s more going on there that I don?t fully understand, because including the same file multiple times per request from multiple files doesn?t seem to trigger it in the simple cases that I?ve been able to come up with that are completely PHP Reader free.

Any ideas would be appreciated. Thanks!

Narsa


Reproduce code:
---------------
The following code in apc_main.c seems to stop the error from occurring:

Inside of apc_request_init and apc_request_shutdown we ALLOC_INIT_ZVAL/array_init/zval_ptr_dtor a Zval for holding the list of filenames loaded this request.

In my_compile_file, right after the initialization of filename:

        /* check if this filename has already been included in this request */
        /* TODO: how do we know this was a require_/include_once? */
        request_filenames = Z_ARRVAL_P(APCG(request_filenames));
        n = zend_hash_find(request_filenames, filename, strlen(filename) + 1, ((void **)&data));
        if (n == SUCCESS && Z_TYPE_PP(data) != IS_NULL) {
                apc_wprint("Already have loaded %s in this request", filename);
                return NULL;
        }

And in the same function, inside of the if (cache_entry != NULL) { ... if (op_array) {  /*here*/ } } block:

            /* Store the name so we can look it up in the duplicate filename check from now on. */
            MAKE_STD_ZVAL(included);
            ZVAL_BOOL(included, 1);
            zend_hash_update(request_filenames, filename, strlen(filename) + 1, &included, sizeof(included), NULL);



Expected result:
----------------
There should be no class redeclaration going on since the require's all have _onces on them.

Actual result:
--------------
We instead get PHP Fatal Errors due to Class Redeclaration. 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-10-05 12:50 UTC] cmb@php.net
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2016-10-05 12:50 UTC] cmb@php.net
According to <https://bugs.php.net/69618>, APC support has been
discontinued in favor of OPcache, APCu, the session upload
progress API and WinCache. Therefore this issue won't get fixed.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Dec 06 21:03:34 2021 UTC