Edit report at https://bugs.php.net/bug.php?id=63359&edit=1
ID: 63359 Comment by: edmond at inbox dot ru Reported by: maciej dot sz at gmail dot com Summary: Defining a interface const with value of another constant triggers fatal error Status: Open Type: Feature/Change Request Package: Scripting Engine problem Operating System: Linux PHP Version: 5.4.8 Block user comment: N Private report: N New Comment: Some problem: OS Windows 7 64-bits Previous Comments: ------------------------------------------------------------------------ [2012-11-19 11:59:16] ahar...@php.net Automatic comment from SVN on behalf of aharvey Revision: http://svn.php.net/viewvc/?view=revision&revision=328423 Log: Warn about configure options that were deprecated in 5.3 and removed in 5.4. Fixes doc bug #63359 (configure: WARNING: unrecognized options: --enable-zend-multibyte). ------------------------------------------------------------------------ [2012-11-14 16:37:32] maciej dot sz at gmail dot com How come a feature request? This is an obvious bug. ------------------------------------------------------------------------ [2012-11-14 15:21:33] larue...@php.net change to feature request. ------------------------------------------------------------------------ [2012-11-14 14:52:29] dagguh at gmail dot com This is especially painful when you are trying to work your way around lack of class literal. <? namespace pl\dagguh\building; class Kitchen implements Room { const CLASS_NAME = "pl\\dagguh\\building\\Kitchen"; } interface Room { const CLASS_NAME = "pl\\dagguh\\building\\Room"; }?> -------- You often need the class name for mocking frameworks. ------------------------------------------------------------------------ [2012-10-25 10:45:43] maciej dot sz at gmail dot com 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 this bug report at https://bugs.php.net/bug.php?id=63359&edit=1