2 added 823 characters in body
source | link

PHP is notnot loosely or strongly, but dynamically typeddynamically typed.

About interfaces, the first thing you should ask yourself is: what are most of the benefits of interfaces?

In OOP, interfaces are not just about types, but about behaviour as well.

Since PHP also has a type hint featuretype hint feature, you can use interfaces just as you would in a pure oo language, such as Java.

interface File
{
    public function getLines();
}

CSVFile implements File
{
    public function getLines()
    {}
}

XMLFile implements File  
{
    public function getLines()
    {}
}

JSONFile implements File 
{
    public function getLines()
    {}
}

class FileReader
{
    public function read(File $file)
    {
    ...    foreach($file->getLines() as $line)
        {
            // do something
        }
    }
}

With PHP interface implementation, you cal also create mocks for abstract classes using PHPUnit - and this is a hell of a feature:

public function testSomething()
{
    $mock = $this->getMockForAbstractClass('File');

    $mock->expects($this->once())
         ->method('getLines')
         ->will($this->returnValue(array()));

    // do your assertions
}

So, basically, you can have a SOLID compatible application in PHP by using the language features, one of them being interfaces.

PHP is not loosely or strongly, but dynamically typed.

About interfaces, the first thing you should ask yourself is: what are most of the benefits of interfaces?

In OOP, interfaces are not just about types, but about behaviour as well.

Since PHP also has a type hint feature, you can use interfaces just as you would in a pure oo language, such as Java.

CSVFile implements File {}

XMLFile implements File {}

JSONFile implements File {}

public function read(File $file)
{
    ...
}

PHP is not loosely or strongly, but dynamically typed.

About interfaces, the first thing you should ask yourself is: what are most of the benefits of interfaces?

In OOP, interfaces are not just about types, but about behaviour as well.

Since PHP also has a type hint feature, you can use interfaces just as you would in a pure oo language, such as Java.

interface File
{
    public function getLines();
}

CSVFile implements File
{
    public function getLines()
    {}
}

XMLFile implements File  
{
    public function getLines()
    {}
}

JSONFile implements File 
{
    public function getLines()
    {}
}

class FileReader
{
    public function read(File $file)
    {
        foreach($file->getLines() as $line)
        {
            // do something
        }
    }
}

With PHP interface implementation, you cal also create mocks for abstract classes using PHPUnit - and this is a hell of a feature:

public function testSomething()
{
    $mock = $this->getMockForAbstractClass('File');

    $mock->expects($this->once())
         ->method('getLines')
         ->will($this->returnValue(array()));

    // do your assertions
}

So, basically, you can have a SOLID compatible application in PHP by using the language features, one of them being interfaces.

1
source | link

PHP is not loosely or strongly, but dynamically typed.

About interfaces, the first thing you should ask yourself is: what are most of the benefits of interfaces?

In OOP, interfaces are not just about types, but about behaviour as well.

Since PHP also has a type hint feature, you can use interfaces just as you would in a pure oo language, such as Java.

CSVFile implements File {}

XMLFile implements File {}

JSONFile implements File {}

public function read(File $file)
{
    ...
}