ScoobyShnacks
ScoobyShnacks

Reputation: 65

PHP Instantiating a Class that Extends an Abstract Class


So I am using an abstract class for the first time in PHP and am struggling to get it working. It is probably simple (as ever!). When I try to instantiate the class B, PHP throws this error

Fatal error: Class 'B' not found in /var/www/test/class/B.class.php on line 12

Abstract Class A

abstract class A
{
    public function A()
    {
        //do something...
    } 
}

Class B

include 'A.class.php';  //abstract class A is in a different file

$b = new B();    //instantiate class B (Line 12, error points to here)

class B extends A
{

    public function B() 
    {
        //do something...
    }

}

Upvotes: 0

Views: 1545

Answers (1)

Jeremy Kendall
Jeremy Kendall

Reputation: 2869

Move $b = new B(); below the class definition.

Upvotes: 2

Related Questions