<?php
namespace Doctrine\Common\Persistence {
interface ObjectRepository
{
public function find($id);
}
}
namespace Doctrine\ORM {
use Doctrine\Common\Persistence\ObjectRepository;
class EntityRepository implements ObjectRepository
{
public function find($id, $lockMode = null, $lockVersion = null) {}
}
}
namespace {
use Doctrine\ORM\EntityRepository;
class MyRepository extends EntityRepository
{
public function find($id) {}
}
}
Fatal error: Declaration of MyRepository::find($id) must be compatible with Doctrine\ORM\EntityRepository::find($id, $lockMode = NULL, $lockVersion = NULL) in /in/2akM2 on line 24
Runnable: https://3v4l.org/2akM2
I think this is a bug in PHP 7.2 and if not, I can't see it mentioned anywhere in changelogs etc, but I thought it might be worth tracking here. Someone else has reported it to PHP: https://bugs.php.net/bug.php?id=75590
This is not a bug in Doctrine and this isn't a bug in PHP either. Your code violates LSP so you are correctly warned about it. I don't think this could even be called BC break as it is obvious bug in user code and also code smell - I would personally call the behavior in 7.1 a bug, since you can never remove a parameter in sub-class.
I suppose the change may be related to Type Widening RFC but I may be wrong.
FYI: PHP bug was closed as _Not a bug_ for exactly the same reason I gave here: LSP violation, fixed in 7.2.