0

I basically want class B to implement a method that's been defined in class A. However when i do so i get the following error.

Strict Standards: Static function A::test() should not be abstract in C:\xampp\htdocs\test1.php on line 4

Here is my PHP code:

<?php
error_reporting( E_STRICT );

abstract class A{
    public abstract static function test();
}

class B extends A {
    public  static function test(){
        echo 'Testing';
    };
}

echo B::test();
MMK
  • 609
  • 5
  • 16

1 Answers1

1

Static methods are not part of the object, so they shouldn't be extended.

Make the method concrete.

I actually struggled with this same problem once I started building unit tests (I almost religiously avoid static methods now, but that's a whole side conversation). Check out this question for someone answering your question berr than I can: Why does PHP 5.2+ disallow abstract static class methods?

Community
  • 1
  • 1
Parris Varney
  • 11,320
  • 12
  • 47
  • 76
  • Could you be more clear ? I definitely want class B to have the method test(). How can i enforce that from class A ? – MMK Jul 08 '15 at 00:49
  • 1
    I updated my answer to be a bit more helpful. But you should really just make the method not-static if you want it to be a part of your class hierarchy. – Parris Varney Jul 08 '15 at 00:59