0

I have classes Video and Audio, which extend class Popular

In class, Video & Audio is a function of "public static function parsing ()" are different in themselves

So, as I can from the class of "Popular" address to the class that calls? That is in a class of "Popular" is a function of "getSong" which has a function call "parsing ()", but here's how to call this function from the class that turns .. Hopefully clearly explained .. Kind of like the opposite function of need "parent"

class Video extends Popular {

    public static function parsing()
    {
        return 'Videooooooooooooo';
        .....
    }

    public static fuinction tratata()
    {
    ....
    }

}

class Audio extends Popular {

    public static function parsing()
    {
       .............
        return 'Audio';
        .....
    }

    public static fuinction tratata()
    {
    ....
    }

}

class Popular {

    public static function getSong()
    {
        $class = '???????';//Video or Audio???
        $class::parsing();// ???
    }

}

Sorry for bad english.. used google traslate

2

2 Answers 2

3

There is no need for this behavior.

Put the parsing function in the Popular class, so that Audio and Video inherit it. Then your getSong just looks like this.

EDIT: self keyword is bound to the class in which the function is defined. So the below is wrong. The correct answer is to use the static keyword instead - IF you are using PHP 5.3.0 or later.

public static function getSong()
{
    static::parsing();
}

below is wrong


public static function getSong()
{
    self::parsing();
}

But really, getSong is no longer needed. When a base class implementation is called on a child class, self still refers to the child class, so the correct parsing function will be called automatically.

Did I understand your question correctly?

Also to everyone else: if I'm wrong about this behavior, then shame on me and I need to go back to school. I haven't used this behavior in a while so I may be rusty.

Sign up to request clarification or add additional context in comments.

1 Comment

Actually, this PHP bug report - bugs.php.net/30934 - says I'm wrong. But also that PHP is being stupid here. Damn you PHP.
0

@Tesserex probaly has the best answer.

Not sure whether this is what you mean, but to find out the class name of the current object:

You seem to be using these functions in static context. That makes things more difficult. As far as I know, the only way to find out in that case is PHP 5.3's get_called_class().

1 Comment

All his method calls are static (dunno why) so I'm not sure he'd have a $this to check. This looks like it might be a late-static-binding issue but the code is pretty confusing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.