Jump to content

Constant in Abstract Classes


sircatsquid

Recommended Posts

Um.. tried Google this but I only find answers about if making constant abstract...I just wonder if I can have constants in an abstract class. Cause I get this error of a undefined constant. This just a example of what I mean and not the actual code, does the same on the other hand.

abstract class testconst {    const YEY = 0;    public function dosomething(){	    if(testconst::YEY == 0)		    return "Awesome!";    }}class test extends testconst {    public function something(){	    return parent::dosomething();    }}

What I was aiming for to have a base class that did some general thing I don't want to define in every class and I wanted to define some options for it.

Link to comment
Share on other sites

Looks like the problem is when I call it from the child class.Tried these two.. still don't work.

parent::YEY testconst::YEY

Edited by sircatsquid
Link to comment
Share on other sites

you can use static::YEY which resolves to current calling class.

Link to comment
Share on other sites

you can use static::YEY which resolves to current calling class.
Yeah, but that didn't work either... why? Well the issue was that I forgot to refer to what class the constant was belonging to when assigning the default value of a privet property in the parent class.Funny cause it said the error was on the line there I was instantiating the child class... very confusing. Thanks anyway for sharing your thoughts, it's appreciated to get some hints.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...