Bug #66773 [Com]: Autoload with Opcache allows importing conflicting class name to namespace

From: Date: Mon, 23 Jun 2014 12:30:39 +0000
Subject: Bug #66773 [Com]: Autoload with Opcache allows importing conflicting class name to namespace
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186302@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66773&edit=1

 ID:                 66773
 Comment by:         jpauli@php.net
 Reported by:        carl dot vuorinen at w3 dot fi
 Summary:            Autoload with Opcache allows importing conflicting
                     class name to namespace
 Status:             Open
 Type:               Bug
 Package:            opcache
 Operating System:   Linux (Ubuntu)
 PHP Version:        5.5.9
 Block user comment: N
 Private report:     N

 New Comment:

Reproduced.
Seems like a bug.

@dmitry: any idea ? I found that the compiler class_table is reseted between each compilation by
opcache (https://github.com/zendtech/ZendOptimizerPlus/blob/master/ZendAccelerator.c#L1411), thus
the class can't be found and detected as already used.


Previous Comments:
------------------------------------------------------------------------
[2014-05-27 01:11:55] adrien dot crivelli at gmail dot com

Same issue here. The test script could be reproduced:

$ lsb_release -a
LSB
Version:	core-2.0-amd64:core-2.0-noarch:core-3.0-amd64:core-3.0-noarch:core-3.1-amd64:core-3.1-noarch:core-3.2-amd64:core-3.2-noarch:core-4.0-amd64:core-4.0-noarch
Distributor ID:	Ubuntu
Description:	Ubuntu 14.04 LTS
Release:	14.04
Codename:	trusty

$ php -v
PHP 5.5.9-1ubuntu4 (cli) (built: Apr  9 2014 17:11:57) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
    with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans

$ php -i | grep opcache.enable_cli
opcache.enable_cli => On => On
$ php execute.php 
self: Some\Bar
parent: Other\Bar

$ php -i | grep opcache.enable_cli
opcache.enable_cli => Off => Off
$ php execute.php 
PHP Fatal error:  Cannot use Other\Bar as Bar because the name is already in use in
/tmp/a/some_foo.php on line 5
PHP Stack trace:
PHP   1. {main}() /tmp/a/execute.php:0
PHP   2. spl_autoload_call() /tmp/a/execute.php:13
PHP   3. {closure:/tmp/a/execute.php:6-8}() /tmp/a/execute.php:0
PHP   4. spl_autoload() /tmp/a/execute.php:7

Fatal error: Cannot use Other\Bar as Bar because the name is already in use in /tmp/a/some_foo.php
on line 5

Call Stack:
    0.0002     235776   1. {main}() /tmp/a/execute.php:0
    0.0005     242720   2. spl_autoload_call() /tmp/a/execute.php:13
    0.0005     242752   3. {closure:/tmp/a/execute.php:6-8}() /tmp/a/execute.php:0
    0.0005     242880   4. spl_autoload() /tmp/a/execute.php:7

------------------------------------------------------------------------
[2014-03-11 12:25:59] carl dot vuorinen at w3 dot fi

Here is a more detailed output with both OPcache enabled and OPcache disabled.
Same behaviour also reproduced in few other environments.

$ php -v      
PHP 5.5.9-1+sury.org~saucy+1 (cli) (built: Feb 13 2014 15:58:58) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
    with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans

$ php -i | grep opcache.enable_cli
opcache.enable_cli => On => On

$ php execute.php                 
self: Some\Bar
parent: Other\Bar

$ sudo nano /etc/php5/cli/php.ini 

$ php -i | grep opcache.enable_cli
opcache.enable_cli => Off => Off

$ php execute.php                 

Fatal error: Cannot use Other\Bar as Bar because the name is already in use 
in /tmp/path/some_foo.php on line 5

Call Stack:
    0.0005     234520   1. {main}() /tmp/path/execute.php:0
    0.0036     241464   2. spl_autoload_call() /tmp/path/execute.php:13
    0.0036     241496   3. {closure:/tmp/path/execute.php:6-8}() /tmp/path/execute.php:0
    0.0036     241624   4. spl_autoload() /tmp/path/execute.php:7

------------------------------------------------------------------------
[2014-02-25 21:29:48] carl dot vuorinen at w3 dot fi

Description:
------------
Autoloading with Opcache enabled allows importing a class from another namespace with a name that is
already in use in the current namespace and the code to execute successfully. Without Opcache the
same code gives Fatal error.

Test script:
---------------
Here is a small sample script with a few files that will be autoloaded by the execute.php script.
Some test results can be found in the comments. 

https://gist.github.com/cvuorinen/e7a19101d40c9fa0a959

Expected result:
----------------
Fatal error: Cannot use Other\Bar as Bar because the name is already in use in
/tmp/path/some_foo.php on line 5

Actual result:
--------------
self: Some\Bar
parent: Other\Bar


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=66773&edit=1


Thread (22 messages)

« previous php.bugs (#186302) next »