-
-
Save cvuorinen/e7a19101d40c9fa0a959 to your computer and use it in GitHub Desktop.
Is this a bug in PHP? Running execute.php on Ubuntu with PHP 5.5.4 executes successfully, but on CentOS with same PHP version it gives Fatal error.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Autoloader that does not need subdirectories (because Gist does not support subdirectories). | |
// Same thing happens with default SPL autoloader where namespaced files are in subdirectories. | |
spl_autoload_register( | |
function($class) { | |
spl_autoload(str_replace("\\", "_", $class)); | |
} | |
); | |
$bar = new Some\Bar(); | |
$foo = new Some\Foo(); | |
$foo->bar($bar); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Other; | |
class Bar { | |
public function baz() { | |
echo "self: " . get_class($this) . "\n"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Some; | |
use Other\Bar as OtherBar; | |
class Bar extends OtherBar { | |
public function baz() { | |
echo "self: " . get_class($this) . "\n"; | |
echo "parent: " . get_parent_class($this) . "\n"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Some; | |
use Other\Bar; | |
class Foo { | |
public function bar(Bar $bar) { | |
$bar->baz(); | |
} | |
} |
Author
cvuorinen
commented
Feb 24, 2014
$ cat /etc/redhat-release
CentOS release 6.4 (Final)
$ cat /proc/version
Linux version 2.6.32-358.18.1.el6.x86_64 (mockbuild@c6b10.bsys.dev.centos.org)
(gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC) ) #1 SMP Wed Aug 28 17:19:38 UTC 2013
$ php -v
PHP 5.5.4 (cli) (built: Sep 19 2013 14:42:22)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
$ php execute.php
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
PHP Stack trace:
PHP 1. {main}() /tmp/path/execute.php:0
PHP 2. spl_autoload_call() /tmp/path/execute.php:13
PHP 3. {closure:/tmp/path/execute.php:6-8}() /tmp/path/execute.php:0
PHP 4. spl_autoload() /tmp/path/execute.php:7
Seems like the culprit is OPcache:
$ 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
Thank you very much, you save my days
I face the same issue but in my case the opcache.enable_cli
flag doesn't actually affect the problem. For now, I don't really know what causes the problem but in my machine the problem does not exist but on the server it exists. In both cases the opcache.enable_cli
is disabled.
My machine (there's no problem)
PHP 7.0.2-4+deb.sury.org~trusty+1 (cli) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
The server (the error gets thrown)
PHP 7.0.0 (cli) (built: Dec 9 2015 09:25:52) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
excellent work.
without opcache:
https://gist.github.com/wandersonwhcr/e16e9dcfb2c54dafa2f84c145b0de983
same problem
5.6.30 - actual
5.5.30,the same issue occurs when opcache is disabled and disappears when opcache is enabled.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment