سؤال

This is what I'm trying to do:

<?php

interface PaymentGatewayInterface {

    public function pay(array $bill);
    public function processNotification($notification);

}

class Payment {

    protected $gateway;

    public function __construct(PaymentGatewayInteface $gateway)
    {
        $this->gateway = $gateway;
    }   

    public function pay(array $bill)
    {
        return $this->gateway->pay($bill);
    }

    public function processNotification($notification)
    {
        return $this->gateway->processNotification($notification);
    }

}

class Paypal implements PaymentGatewayInterface {

    public function pay(array $bill)
    {
    }

    public function processNotification($notification)
    {
    }

}

$a = new Payment(new Paypal);

This is the error I'm receiving from PHP:

Catchable fatal error: Argument 1 passed to Payment::__construct() must be an instance of PaymentGatewayInteface, instance of Paypal given, called in /in/oP75h on line 43 and defined in /in/oP75h on line 14

Here you can test it yourself: http://3v4l.org/oP75h

I was first working in Laravel 4 and Mockery (TDD), but after sometime debugging it I realized this is "just" a PHP problem, actually.

هل كانت مفيدة؟

المحلول

You have a typo:-

public function __construct(PaymentGatewayInteface $gateway)
                                              ^ 'r' missing

Should be:-

public function __construct(PaymentGatewayInterface $gateway)

You are missing the 'r' in interface.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top