Skip to content

Instantly share code, notes, and snippets.

@darraghenright
Created September 27, 2013 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darraghenright/6733690 to your computer and use it in GitHub Desktop.
Save darraghenright/6733690 to your computer and use it in GitHub Desktop.
A class that implements an interface cannot override a constant defined in the interface. But any child class that extends from the implementing class... can?
<?php
/**
* A class that implements an interface cannot
* override a constant defined in the interface.
* But any child class that extends from the
* implementing class... can?
*
* o_O
*/
interface FooInterface
{
/**
* Define a constant
*/
const FOO = 'foo';
}
class Bar implements FooInterface
{
/**
* As noted in the PHP docs:
*
* An implementing class can
* not override an interface
* defined constant...
*/
const FOO = 'bar'; // FATAL ERROR!
}
class Baz extends Bar
{
/**
* However, a child of an
* implementing class can
* override an interface
* defined constant :)
*/
const FOO = 'baz'; // WORKS!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment