0
<?
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**
5
Contributors
4
Replies
19
Views
2 Years
Discussion Span
Last Post by diafol
0

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.