Re: Possible Bug with Interface, Constants and Inheritance
| From: | Andreas Heigl | Date: | Mon, 27 Jun 2016 15:46:49 +0000 |
| Subject: | Re: Possible Bug with Interface, Constants and Inheritance | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-94284@lists.php.net to get a copy of this message | ||
Am 27.06.16 um 17:41 schrieb Bishop Bettini:
> On Mon, Jun 27, 2016 at 11:31 AM, Andreas Heigl <andreas@heigl.org> wrote:
>
>> Am 27.06.16 um 15:28 schrieb Karl Pflästerer:
>>> Andreas Heigl <andreas@heigl.org> writes:
>>>
>>>> Am 27.06.16 um 15:01 schrieb Karl Pflästerer:
>>>>> interface I1 { const C1 = '';}
>>>>> class C3 implements I1 { const C1 = 'c2';}
>>>>> $c3 = new C3;
>>>>> var_dump($c3::C1);
>>>>
>>>> According to https://3v4l.org/jIcs6 it looks like
>>>> that's intended
>>>> behaviour ;)
>>>
>>> But why does it work in the CLI if I write the code (instead of using a
>>> script)? That's my question.
>>
>> It doesn't. At least not on my machine. This is the output I get:
>>
>> $ php -v
>> PHP 7.1.0alpha2 (cli) (built: Jun 24 2016 13:50:28) ( NTS )
>> Copyright (c) 1997-2016 The PHP Group
>> Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies
>>
>
> Technically, this is a different version than reported. Nonetheless, on the
> same version my REPL complains as well, I suspect because the original
> report misspelled the INI setting ("-ddispplay_errors=On", notice the
> double "p"):
>
> $ php -v
> PHP 7.0.7 (cli) (built: May 28 2016 08:26:36) ( NTS )
> Copyright (c) 1997-2016 The PHP Group
> Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
> with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend
> Technologies
> with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans
>
> $ php -a
> Interactive shell
>
> php > interface I1 { const C1 = ''; }
> php > class C3 implements I1 { const C1 = 'c2'; }
> PHP Fatal error: Cannot inherit previously-inherited or override constant
> C1 from interface I1 in php shell code on line 1
> PHP Stack trace:
> PHP 1. {main}() php shell code:0
>
>
>
>> So it crashes with a fatal error when Implementing the interface. It'S
>> interesting though that the script allows me to instantiate the class
>> nonetheless. That's right.
>>
>
> Under normal interpretive operation, the Fatal terminates the script. But
> in the case of the REPL command line, those are swallowed up and you can
> keep going. Same as like:
>
> php > foo();
> PHP Warning: Uncaught Error: Call to undefined function foo() in php shell
> code:1
> Stack trace:
> #0 {main}
> thrown in php shell code on line 1
> PHP Stack trace:
> PHP 1. {main}() php shell code:0
> php > echo 'hi';
> hi
>
> I'm not seeing any bugs here.
Thanks for the info.
What I find strange is that I can instantiate the class "C3" even though
the declaration of the class is broken. I wouldn't say it's a bug, but
interesting.
Cheers
Andreas
--
,,,
(o o)
+---------------------------------------------------------ooO-(_)-Ooo-+
| Andreas Heigl |
| mailto:andreas@heigl.org N
50°22'59.5" E 08°23'58" |
| http://andreas.heigl.org http://hei.gl/wiFKy7 |
+---------------------------------------------------------------------+
| http://hei.gl/root-ca
|
+---------------------------------------------------------------------+
Attachment: [application/pkcs7-signature] S/MIME Cryptographic Signature smime.p7s
Attachment: [application/pkcs7-signature] S/MIME Cryptographic Signature smime.p7s