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(); ?>
All functions in the interface are implicitly abstract. There is no need to use the abstract keyword when declaring a function.
, , , , , . , , public abstract function, , , , connect. , , .
public abstract function
connect
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.
Source: https://habr.com/ru/post/1764327/More articles:Capturing video with an open window in window forms - c ++javax.persistence / hibernate inside the game - hibernateUri.MakeRelativeUri Behavior On Mono - c #Understanding jquery - constructor error? - javascriptОтображение локального потока gstreamer в браузере - javascriptHow do I look like the usual transaction confirmation procedure on multiple sites? - javaWordPress posts sorted by category and year - sortingHow do you work with IDisposable sequences using LINQ? - c #WPF distinguishes between coding-SelectionChanged and mouse-SelectionChanged - eventsHow does Big O relate to N + 1? - big-oAll Articles