#49472 [Ver]: Constants defined in Interfaces can be overridden

From: Date: Sun, 13 Sep 2009 18:47:45 +0000
Subject: #49472 [Ver]: Constants defined in Interfaces can be overridden
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-142303@lists.php.net to get a copy of this message
 ID:               49472
 Updated by:       jani@php.net
 Reported By:      phil at mossyvale dot co dot uk
 Status:           Verified
 Bug Type:         Class/Object related
 Operating System: *
 PHP Version:      5.*, 6
 New Comment:

<?php

interface ia {
    const c = 'Sea';
}

class Foo implements ia {
	
	// const c = "Lake";  
	
	// Attempting to override ia's constant c in
	// this class triggers a fatal error.
	
}

class FooBar extends Foo implements ia {
	
	const c = 'Ocean'; // No error, class constant
	 		   // overriding ia's definition.
	
	public function show(){
		// ia's definition is still accessible.
	  return ia::c;
	}
}

$i = new FooBar;
echo FooBar::c;
echo $i->show();

?>


Previous Comments:
------------------------------------------------------------------------

[2009-09-05 10:08:19] phil at mossyvale dot co dot uk

Description:
------------
If an interface defines a constant and is then implemented by a class
which is then extended with a further class and both classes implement
the interface, the second class may override the interface constant
without a fatal error. Also present in 5.2.10 on FreeBSD 7.2

Reproduce code:
---------------
---
From manual page: language.oop5.interfaces
---
http://codepad.org/vStYX1Kz

Expected result:
----------------
Fatal error:  Cannot inherit previously-inherited constant c from
interface ia ... on line 18

Actual result:
--------------
Program outputs "OceanSea" which indicates that the interface constant
is still available but the class constant with the same name overrides
it.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=49472&edit=1



Thread (5 messages)

« previous php.bugs (#142303) next »