Re: Accessing child constants from base class

From: Date: Fri, 10 Oct 2003 17:40:16 +0000
Subject: Re: Accessing child constants from base class
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-4785@lists.php.net to get a copy of this message
Hi Ard- Sorry, I must of misunderstood you. Yes, that would work fine. Now copy/paste the getElementName() function in the derived class to all 100's of other derived classes and wonder why you couldn't just do this with one base class function. :) Dan Cox Ard Biesheuvel wrote:
This works fine for me: abstract class Base {
        abstract function getElementName();
        function getName()
        {
                return $this->getElementName();
        }
} class Derived extends Base {
        const ElementName = 'DerivedElementName';
        function getElementName()
        {
                return ElementName;
        }
} $c = new Derived(); echo $c->getName();


« previous php.internals (#4785) next »