我在构建的Laravel 4应用程序中遇到了一个非常奇怪的问题,尽管这个问题与PHP的关系比Laravel更相关:PHP抱怨当接口和类方法具有完全相同的签名时,这些方法不兼容。
例如,当使用了不正确的类型提示,或者参数数量不一致时,它应该只抱怨,但由于某种原因,当一切都正确时,这是在抱怨。我看不到其他遇到此问题的人,任何人都可以看到我没有看到的东西吗?
界面:
<?php
namespace Repository;
interface TillRepositoryInterface {
public static function allInVenue(Venue $venue);
public static function findByIdInVenue(Venue $venue);
}
实现接口的存储库类:
<?php
class TillRepository extends BaseRepository implements Repository'TillRepositoryInterface {
public static function allInVenue(Venue $venue)
{
}
public static function findByIdInVenue(Venue $venue)
{
}
}
似乎在发布问题几秒钟后,我的大脑打开了:
事实上,我在界面中使用了命名空间,所以(Venue $venue)
实际上是(Repository'Venue $venue)
。只需更改此设置:
public static function allInVenue(Venue $venue);
public static function findByIdInVenue(Venue $venue);
对此
public static function allInVenue('Venue $venue);
public static function findByIdInVenue('Venue $venue);
解决了问题。保持这一点,以防其他人偶然发现同样的错误,以避免头痛