Let us imagine, we have following declaration of interface.

```
<?php 
namespace App\Sample;

interface A
{
    public function doSomething();
}

```

and class `B` that implements interface `A`.

```
<?php
namespace App\Sample;

class B implements A
{
    public function doSomething()
    {
        //do something
    }

    public function doBOnlyThing()
    {
        //do thing that specific to B
    }  
}

```

Class `C` will depends on interface `A`.

```
<?php
namespace App\Sample;

class C
{
    private $a;

    public function __construct(A $a)
    {
        $this->a = $a;
    }

    public function doManyThing()
    {
        //this call is OK
        $this->a->doSomething();

        //if $this->a is instance of B, 
        //PHP does allow following call
        //how to prevent this?
        $this->a->doBOnlyThing();            
    }  
}

...
(new C(new B()))->doManyThing();

```

If instance class `B` is passed to `C`, PHP does allow call to any public methods of B even though we typehint constructor to accept `A` interface only.

How can I prevent this with the help of PHP, instead of relying on any team members to adhere interface specification?

**Update** : Let us assume I can not make `doBOnlyThing()` method private as it is required in other place or it is part of third-party library that I can not change.