PHP: abstract method in interface

Why can't I declare an abstract method in an interface? This is my code. Thank.

<?php
interface Connection {
    public abstract function connect();
    public function getConnection();
}

abstract class ConnectionAbstract implements Connection() {
    private $connection;

    public abstract function connect();

    public function getConnection() {
        return $this->connection;
    }
}

class MySQLConnection extends ConnectionAbstract {
    public function connect() {
        echo 'connecting ...';
    }
}

$c = new MySQLConnection();
?>
+3
source share
3 answers

All functions in the interface are implicitly abstract. There is no need to use the abstract keyword when declaring a function.

+13
source

, , , , , . , , public abstract function, , , , connect. , , .

+6

Both methods in the Connection interface are abstract. All methods in the interface are implicitly abstract. Therefore, the connect () method does not require an abstract keyword.

+1
source

Source: https://habr.com/ru/post/1764327/


All Articles