Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaration of method must be compatible with that of interface method - when method signatures are exactly the same?

I've come across a very strange problem in a Laravel 4 application I'm building, although this question pertains more to PHP than Laravel: PHP is complaining that these methods are incompatible when both interface & class methods have exactly the same signature.

It should only complain if, for instance, the incorrect type hint is used, or there are an inconsistent number of arguments, but for some reason this is complaining when everything is done right. I can't see anyone else who has had this problem, can anyone see anything I'm not seeing?

The interface:

<?php
namespace Repository;

interface TillRepositoryInterface {
    public static function allInVenue(Venue $venue);

    public static function findByIdInVenue(Venue $venue);
}

The repository class that implements the interface:

<?php

class TillRepository extends BaseRepository implements Repository\TillRepositoryInterface {

    public static function allInVenue(Venue $venue)
    {

    }

    public static function findByIdInVenue(Venue $venue)
    {

    }
}
like image 442
SixteenStudio Avatar asked Nov 20 '25 16:11

SixteenStudio


1 Answers

Seems seconds after posting the question my brain switched on:

It was the fact that I was using a namespace in the interface, so (Venue $venue) was actually (Repository\Venue $venue). Simply changing this:

public static function allInVenue(Venue $venue);

public static function findByIdInVenue(Venue $venue);

To this

public static function allInVenue(\Venue $venue);

public static function findByIdInVenue(\Venue $venue);

Solved the issue. Keeping this up in case anyone else stumbles across the same mistake, to avoid headaches

like image 121
SixteenStudio Avatar answered Nov 23 '25 06:11

SixteenStudio