Skip to content

Instantly share code, notes, and snippets.

@cvuorinen
Last active May 26, 2017 09:47
Show Gist options
  • Save cvuorinen/e7a19101d40c9fa0a959 to your computer and use it in GitHub Desktop.
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.
<?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);
<?php
namespace Other;
class Bar {
public function baz() {
echo "self: " . get_class($this) . "\n";
}
}
<?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";
}
}
<?php
namespace Some;
use Other\Bar;
class Foo {
public function bar(Bar $bar) {
$bar->baz();
}
}
@ivorobioff
Copy link

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

@caritasem
Copy link

excellent work.

@wandersonwhcr
Copy link

wandersonwhcr commented Aug 11, 2016

@hack3p
Copy link

hack3p commented Mar 15, 2017

5.6.30 - actual

@lovelock
Copy link

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