programing

PHP: 클래스는 "Call to private method ... from context ..." 문제를 확장합니다.

bestprogram 2023. 10. 9. 23:26

PHP: 클래스는 "Call to private method ... from context ..." 문제를 확장합니다.

WordPress에는 3개의 클래스가 있습니다. (질문 자체는 이와 무관함)

class WP_Widget

class Theme_Widget extends WP_Widget

class Specific_Widget extends Theme_Widget

기본적으로 Theme_Widget에는 기본 WP_Widget에 대한 일부 확장 기능이 포함되어 있습니다.

Specific_Widget 내부에서 테마_Widget의 메소드 중 하나를 호출합니다.

class Specific_Widget {

    function __construct() {
         $this->some_method_that_belongs_to_Theme_Widget();
    }
}

Specific_Widget을 인스턴스화하면 PHP는 다음과 같은 치명적인 오류를 발생시킵니다.

Fatal error: Call to private method Theme_Widget::some_method_that_belongs_to_Theme_Widget() from context 'Specific_Widget' in ...

이 문제를 어떻게 해결할 수 있을지 아이디어가 있습니까?PHP에서 이 오류를 받은 것은 이번이 처음입니다.워드프레스 자체에서 비롯된 것일까요?

메서드를 선언해야 합니다.protected,보다는private, 아동 수업이 그것을 사용할 수 있기를 원한다면요.

사용하다protected functionURL의 보호된 기능을 전달하지 않고 확장 클래스의 하위 기능에 액세스하려면

예를들면

protected function somemethod() { // your code goes here }

언급URL : https://stackoverflow.com/questions/3007020/php-class-extends-problem-call-to-private-method-from-context