Posts

Showing posts from June, 2014

PHP Interfaces

Lots of developers struggle to grasp the concept of the "interface" in PHP. But once they get the idea and understand how it works, they then struggle with a new problem: writing interfaces that are too complicated. This might seem like a contradiction in terms: after all, we want to create comprehensive interfaces that describe the behaviour of a particular object type. And since we don't generally want to extend the interface, shouldn't the interface we write be complete? Yes, and no. Let me explain. The overbearing interface Let's take a look at a common database interface that many of developers come up with when they're tasked with writing a database layer: <?php     interface MyDBObject {         public function connect($host, $db, $user, $pass);         public function query($query, array $params);         public function prepare($query);         public function beginTransaction();         public function commit();         public f