php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49472 Constants defined in Interfaces can be overridden
Submitted: 2009-09-05 10:08 UTC Modified: 2009-12-03 12:35 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: phil at mossyvale dot co dot uk Assigned: felipe (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.*, 6 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: phil at mossyvale dot co dot uk
New email:
PHP Version: OS:

 

 [2009-09-05 10:08 UTC] 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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-13 18:47 UTC] jani@php.net
<?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();

?>
 [2009-12-03 12:34 UTC] svn@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&revision=291642
Log: - Fixed bug #49472 (Constants defined in Interfaces can be overridden)
 [2009-12-03 12:35 UTC] felipe@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Feb 01 13:01:29 2025 UTC