Bug #76725 [NEW]: Self-referencing constant fatal error in specific case

From: Date: Thu, 09 Aug 2018 12:57:21 +0000
Subject: Bug #76725 [NEW]: Self-referencing constant fatal error in specific case
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-216696@lists.php.net to get a copy of this message
From:             martin dot ninov at gmail dot com
Operating system: Ubuntu16.04 and W10
PHP version:      7.2.8
Package:          *General Issues
Bug Type:         Bug
Bug description:Self-referencing constant fatal error in specific case

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 bug report at https://bugs.php.net/bug.php?id=76725&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=76725&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=76725&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=76725&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=76725&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=76725&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=76725&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=76725&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=76725&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=76725&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=76725&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=76725&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=76725&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=76725&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76725&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=76725&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=76725&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=76725&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76725&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=76725&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=76725&r=mysqlcfg



Thread (6 messages)

« previous php.bugs (#216696) next »