0

I want to overwrite a static method with a non static method. I'm getting this error:

Fatal error: Cannot make static method Person::say() non static in class Coder on line 22

I want to overwrite a classes parent static method makeCall() with a more specific makeCall() that would be non-static.

Code:

<?php

class Request {

    public static function makeCall($url) {

        // Do some cURL stuff...

    }
}

class API extends Request {

    const PRODUCTS = '/products';

    private $api;

    public function __construct($api) {

        $this->api = $api;
    }

    public function getProducts() {

        $this->makeCall(self::PRODUCTS);
    }

    public function makeCall($service) {

        parent::makeCall($this->api . $service);
    } 
}

I could make the parent makeCall() non-static, but I also want to be able to Request:makeCall() in some places.

4

1 回答 1

2

您可以简单地更改您的方法名称。并用新名称称呼它。

没有选项可以将其与您要扩展的类的静态方法同名。

于 2013-05-22T20:00:23.107 回答