<?
abstract class BaseData
{
    protected $connection;

    public function __construct($connection)
    {
        $this->connection = $connection;
    }

    abstract public function connected();
    abstract public function get();
}

class UserData extends BaseData
{
    public function exists()
    {
        return is_connected($this->connection);
    }

    public function get()
    {
        return get_data($this->connection);
    }
}
$UserData = new UserData(new Connection());
?>

In the above program i`m getting the follwing error: In line 26;

**Fatal error: Class UserData contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (BaseData::connected) in E:\xampp\htdocs\Antony\161214\Abstract\abstract6.php on line 26**

Recommended Answers

All 4 Replies

The BaseData class has 2 abstract methods: connected() and get(). The UserData class provides an implementation for the get() function but there is still no implementation for the connected() function. The error message is telling you that either you must declare the UserData class abstract or you must provide an implementation for the connected() function.

I totally agree with the above response. Once you declare an abstract method within abstract class, it will impose a mandatory must have method in the child class.

Unlike, in factory pattern a class can also be written in abstract class without abstract method, but methods within the abstract class can return a clone of an instance of a class from different namespaces.

And this post should be in Java instead of PHP...

Member Avatar for diafol

@Taywin

Why?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.