Snooker with Abstract - PHP

I have an abstract class that I inherit from:

abstract class Test
{
    public function GetTests()
    {
    }
}

and I have a specific question that most of the time I use the implementation of abstract classes:

class Concrete extends Test
{
    // No problemmos
}

I recently had to implement a different version of the GetTests method, and actually I wanted to overwrite it, as it is built into my entire routing:

class Concrete extends Test
{
    public function GetTests( $newArgument )
    {
        // notice $newArgument
    }
}

However, I get this error message:

Declaration of Concrete::GetTests() should be compatible with Test::GetTests()

Besides copying the entire function from the abstract class to this particular one, although I only need to implement this method differently ... Is there a way around this?

I understand that I could:

abstract class Test
{
    abstract public function GetTests();
}

But that's why I am a snooker, because I no longer have the opportunity to modify how the base class Test ... doh is implemented! ... If I really don't need to ...


Thanks to all the great answers ...

( , ), Test Concrete, Test, Test... , ( ) ...

:

/* no longer abstract */ class UnitOfWorkController
{
    public function GetUnits()
    {
        // Implementation
        return View::make(...);
    }
}

...

class SomethingController /* no longer extends the UnitOfWorkController */
{
    private $unitOfWorkController;
    public function __Construct()
    {
        $this->unitOfWorkController = new UnitOfWorkController();
    }

    public function GetUnits()
    {
        return $this->unitOfWorkController->GetUnits();
        // or I could just implement my own junk
    }
}
+2
4

, , , , X , X .

, Test GetTests. , , , . , , .

, :

$object = new Test;
$test -> GetTests ();

Test . , , Test, GetTests, . , , , , , .

PHP , OO , , , . , , , .

+1

​​ , , . .

, , ArgumentType .

public function something(ArgumentType $Argument)
{
}

, null :

public function something(ArgumentType $Argument = null)
{
}

.

PHP . http://php.net/manual/en/language.oop5.abstract.php:

[...] , , .. . , , , .

+1

Concrete::GetTests() , Test::GetTests() - . Test, . .

:

  • $newArgument Test::GetTests().
  • $newArgument Concrete::GetTests().
  • Concrete::GetTests() .
+1

PHP , . , ,

, : http://php.net/manual/en/language.oop5.overloading.php#object.call

- , "" ( ), .

, , , . , , , .

, , "" . , , .

+1

All Articles