Am 27.06.16 um 15:28 schrieb Karl Pflästerer: > Andreas Heigl <[email protected]> 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
$ 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
Fatal error: Cannot inherit previously-inherited or override
constant C1 from interface I1 in php shell code on line 1
php > $c3 = new C3;
php > var_dump($c3::C1);
string(2) "c2"
php >
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.
Perhaps some C-Guru can shed some light here?
Cheers
Andreas
--
,,,
(o o)
+---------------------------------------------------------ooO-(_)-Ooo-+
| Andreas Heigl |
| mailto:[email protected] N 50°22'59.5" E 08°23'58" |
| http://andreas.heigl.org http://hei.gl/wiFKy7 |
+---------------------------------------------------------------------+
| http://hei.gl/root-ca |
+---------------------------------------------------------------------+
smime.p7s
Description: S/MIME Cryptographic Signature
