From: maciej dot sz at gmail dot com Operating system: Linux PHP version: 5.4.8 Package: Scripting Engine problem Bug Type: Bug Bug description:Defining a interface const with value of another constant triggers fatal error
Description: ------------ When a constant is defined in an interface with a value of another class or interface constant, a fatal error is triggered: Fatal error: Cannot inherit previously-inherited or override constant FOO from interface IMyInterface in Bar.php on line 3 To reproduce this following conditions must be met (took me 2 days to figure this out): - the constant value must be defined as another class/interface constant - classes and interfaces must be autoloaded on demand - two classes must implement the interface - one class must inherit the other one - the super class must be instantiated before the sub class Seems like this is related to bug #33732 and bug #38286 but is still not fixed. Test script: --------------- File IMyInterface.php: ---------------------- <?php interface IMyInterface { // Use any class or interface constant as value of FOO. // I'll just use some constant available out of the box, to keep it simple: const FOO = FilesystemIterator::CURRENT_AS_PATHNAME; } File Foo.php: ---------------------- <?php class Foo implements IMyInterface {} File Bar.php: ---------------------- <?php class Bar extends Foo implements IMyInterface {} File index.php: ---------------------- <?php date_default_timezone_set('Europe/Warsaw'); spl_autoload_register(function($cname){ if ( class_exists($cname, false) || interface_exists($cname, false) ) { return; } require_once "{$cname}.php"; }); // Foo is super-class for Bar. // uncomment below line to trigger the error: $F = new Foo(); // this should run without errors at any time, but if Foo is instantiated // prior to this line, then the error is triggered: $B = new Bar(); Expected result: ---------------- No errors, the code is correct. Actual result: -------------- Fatal error: Cannot inherit previously-inherited or override constant FOO from interface IMyInterface in Bar.php on line 3 -- Edit bug report at https://bugs.php.net/bug.php?id=63359&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=63359&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=63359&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=63359&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=63359&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=63359&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=63359&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=63359&r=needscript Try newer version: https://bugs.php.net/fix.php?id=63359&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=63359&r=support Expected behavior: https://bugs.php.net/fix.php?id=63359&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=63359&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=63359&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=63359&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63359&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=63359&r=dst IIS Stability: https://bugs.php.net/fix.php?id=63359&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=63359&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=63359&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=63359&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=63359&r=mysqlcfg