Possible Bug with Interface, Constants and Inheritance
| From: | (Karl Pflästerer) | Date: | Mon, 27 Jun 2016 13:01:50 +0000 |
| Subject: | Possible Bug with Interface, Constants and Inheritance | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-94276@lists.php.net to get a copy of this message | ||
Hi,
I'm not sure if it's a bug or not.
Consider these simple script:
<?php
interface I1 { const C1 = '';}
class C3 implements I1 { const C1 = 'c2';}
$c3 = new C3;
var_dump($c3::C1);
That gives a fatal error with mod_php and PHP CLI if I call the CLI
version with a file name:
PHP Fatal error: Cannot inherit previously-inherited or override
constant C1 from interface I1 in
If I use the CLI and enter the code directly it works:
~> php -v
PHP 7.0.7 (cli) (built: May 27 2016 15:22:32) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
~> php -a -ddispplay_errors=On
Interactive shell
php > interface I1 { const C1 = '';}
php > class C3 implements I1 { const C1 = 'c2';}
php > $c3 = new C3;
php > var_dump($c3::C1);
string(2) "c2"
Is this always the correkt behaviour?
KP