Bug #76725 [Fbk->Opn]: Self-referencing constant fatal error in specific case

From: Date: Thu, 09 Aug 2018 13:24:34 +0000
Subject: Bug #76725 [Fbk->Opn]: Self-referencing constant fatal error in specific case
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-216699@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76725&edit=1 ID: 76725 Updated by: nikic@php.net Reported by: martin dot ninov at gmail dot com Summary: Self-referencing constant fatal error in specific case -Status: Feedback +Status: Open Type: Bug -Package: Scripting Engine problem +Package: *General Issues Operating System: Ubuntu16.04 and W10 PHP Version: 7.2.8 Block user comment: N Private report: N New Comment: So generally, the code either failing or not failing is fine in this case. It can fail because that constant declaration is clearly illegal, it can not fail because the constant is not actually used. But there's definitely something fishy going on here. While the impact of the property declaration doesn't surprise me much (probably triggers a full class initializer resolution), I don't see how the namespace declaration should impact this. Previous Comments: ------------------------------------------------------------------------ [2018-08-09 13:05:51] martin dot ninov at gmail dot com The bug is that somehow a bunch of unrelated statements cause the code to fail. Also, I misspoke when I said 'constant assignment', I meant the 'property declaration' indeed. ------------------------------------------------------------------------ [2018-08-09 13:01:37] nikic@php.net What exactly is the bug here? That there is no error if the property declaration is removed? ------------------------------------------------------------------------ [2018-08-09 12:57:21] martin dot ninov at gmail dot com Description: ------------ The test script generates a Fatal error: Uncaught Error: Cannot declare self-referencing constant 'self::FOO' All lines of test script are required, except the last line, which is just there to output something. Removing any of the following eliminates the error: namespace second constant constant assignment I tested on a number on both win10 and linux(ubuntu 16.04), and a number of php 7.2 versions. This: https://3v4l.org/3aIHb says it works on php5.6 versions and fails in php7.0+ Test script: --------------- <?php namespace Waffles; abstract class A { const FOO = self::FOO; const OTHER = 0; private $waf = self::OTHER; } class B extends A { const FOO = 'waffles'; } $foo = new B(); echo $foo::FOO; Expected result: ---------------- waffles Actual result: -------------- Fatal error: Uncaught Error: Cannot declare self-referencing constant 'self::FOO' ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76725&edit=1

« previous php.bugs (#216699) next »