/ Published in: 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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php 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! }
Comments
