w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Do child classes inherit parent constants and if so how do I access them?

I think you would need to access it like this:


or "parent", as was mentioned.


One thing that is interesting to note is that you can actually override the const value in your child class.

class MyParentClass{

    const CONSTANT_1=1

class MyChildClass extends MyParentClass{

    const CONSTANT_1=2

echo MyParentClass::CONSTANT_1 // outputs 1
echo MyChildClass::CONSTANT_1  // outputs 2

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.