Bug #68185 [NEW]: 'PHP Fatal error: Inconsistent insteadof definition.' - incorrectly triggered
| From: | marc at dotfive dot co dot uk | Date: | Wed, 08 Oct 2014 09:14:34 +0000 |
| Subject: | Bug #68185 [NEW]: 'PHP Fatal error: Inconsistent insteadof definition.' - incorrectly triggered | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-187952@lists.php.net to get a copy of this message | ||
From: marc at dotfive dot co dot uk
Operating system: Debian Wheezy/Jessie
PHP version: 5.6.1
Package: Class/Object related
Bug Type: Bug
Bug description:'PHP Fatal error: Inconsistent insteadof definition.' - incorrectly
triggered
Description:
------------
'PHP Fatal error: Inconsistent insteadof definition.' - This error is
triggered incorrectly and very unpredictably on classes with many
traits. Reproducing this bug is very difficult, as the outcome is
affected by seemingly irrelevant things. This has been found in versions
5.4 through to 5.6.1 and appears to have been introduced by commit
520d07d86a7520c970e18480ed0237c6253bd097, which fixed Bug #61052:
"missing error check in trait 'insteadof' clause"
This inconsistant behaviour appears to be caused by an incorrect index
when checking if the included trait method is in exclude_from_classes.
In the code below from zend_compile.c
cur_precedence->exclude_from_classes[i] should, I believe, be
cur_precedence->exclude_from_classes[j] (i.e. the 'i' should be a 'j'):
zend_compile.c
----------------------------
/* make sure that the trait method is not from a class mentioned in
exclude_from_classes, for consistency */
if (cur_precedence->trait_method->ce ==
cur_precedence->exclude_from_classes[i]) {
zend_error(E_COMPILE_ERROR,
"Inconsistent insteadof definition. "
Test script:
---------------
The following script is split across two files, 'test' and 'class.php'.
I have been unable to create a script in a single file that incorrectly
triggers the error. The first file, test, creates a bunch of empty
classes and includes class.php, which defines a classes with traits and
uses 'insteadof'. Changing the number of empty classes that are created
in test changes whether or not the error triggers, as does changing the
number of traits in class.php. Even seemingly irrelevant things change
whether the error triggers; adding something like an 'echo' at the
beginning of the script, or running the script from a different
directory changes this behaviour.
test:
------------------------
#!/usr/bin/php -q
<?php
$i = 17;
while ($i--) {
eval('class c' . $i . ' {}');
}
require_once("class.php");
die("End");
class.php:
-----------------------
<?php
namespace SPACE;
trait trait0 { public function methodName() {} }
trait trait1 { public function methodName() {} }
trait trait2 { public function methodName() {} }
trait trait3 { public function methodName() {} }
trait trait4 { public function methodName() {} }
trait trait5 { public function methodName() {} }
trait trait6 { public function methodName() {} }
trait trait7 { public function methodName() {} }
class c {
use trait0,
trait1,
trait2,
trait3,
trait4,
trait5,
trait6,
trait7
{
trait0::methodName insteadof trait1;
trait0::methodName insteadof trait2;
trait0::methodName insteadof trait3;
trait0::methodName insteadof trait4;
trait0::methodName insteadof trait5;
trait0::methodName insteadof trait6;
trait0::methodName insteadof trait7;
}
}
Expected result:
----------------
# ./test
End
Actual result:
--------------
# ./test
PHP Fatal error: Inconsistent insteadof definition. The method
methodName is to be used from SPACE\trait0, but SPACE\trait0 is also on
the exclude list in /root/class.php on line 79
--
Edit bug report at https://bugs.php.net/bug.php?id=68185&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68185&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68185&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68185&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=68185&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=68185&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=68185&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=68185&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=68185&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=68185&r=support
Expected behavior: https://bugs.php.net/fix.php?id=68185&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=68185&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=68185&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=68185&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68185&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=68185&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=68185&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=68185&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68185&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=68185&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=68185&r=mysqlcfg