Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从父主题调用类发布Wordpress_Php_Wordpress - Fatal编程技术网

Php 从父主题调用类发布Wordpress

Php 从父主题调用类发布Wordpress,php,wordpress,Php,Wordpress,我有一个Wordpress父主题,我的子主题扩展了很多功能。但我的问题是,当我想在我的子主题文件夹结构中使用或扩展父主题文件夹中的类时,会出现“未定义类”或“未找到类”的错误 使用父主题中的类的正确方法是什么 以下是其中一个类的示例: class MyNewClass extends ReadAndDigestWidget {} 该类将在其内部调用更多来自父主题的类 非常感谢您在深入理解Wordpress和php方面提供的任何帮助 PHP在设计上不是一种面向对象的语言,因此结果有时可能微不足

我有一个Wordpress父主题,我的子主题扩展了很多功能。但我的问题是,当我想在我的子主题文件夹结构中使用或扩展父主题文件夹中的类时,会出现“未定义类”或“未找到类”的错误

使用父主题中的类的正确方法是什么

以下是其中一个类的示例:

class MyNewClass extends ReadAndDigestWidget {} 
该类将在其内部调用更多来自父主题的类


非常感谢您在深入理解Wordpress和php方面提供的任何帮助

PHP在设计上不是一种面向对象的语言,因此结果有时可能微不足道。下面是一个在PHP中如何进行继承的基本示例

class ChildTheme extends ParentTheme {
       function parentDropDownMenu(){
           parent::dropDownMenu();
           //do additionall stuff
       }
    }

theme = new ParentTheme();
$theme->dropDownMenu();  // will call the parent function directly
$theme->parentDropDownMenu();     // will call the function override

通常,我甚至不会在PHP中重写父类的类方法,而只是在无法完全控制父类的情况下扩展该类。如果升级发生在wordpress中,而您覆盖了必需的升级,该怎么办?

PHP不是一种OOP语言,因此其设计结果有时可能微不足道。下面是一个在PHP中如何进行继承的基本示例

class ChildTheme extends ParentTheme {
       function parentDropDownMenu(){
           parent::dropDownMenu();
           //do additionall stuff
       }
    }

theme = new ParentTheme();
$theme->dropDownMenu();  // will call the parent function directly
$theme->parentDropDownMenu();     // will call the function override

通常,我甚至不会在PHP中重写父类的类方法,而只是在无法完全控制父类的情况下扩展该类。如果升级发生在wordpress中,而您覆盖了必需的升级,该怎么办?

我了解继承是如何工作的。我的难题是扩展或使用父主题类。我想在子主题中创建一个新类,该类使用父主题中包含的类进行扩展。但是,当我这样做时,在子主题的functions.php中初始化它。我得到一个错误,说我创建的新类找不到我扩展它的父类。这有意义吗?如何使用父主题中的子主题中的类,因为据我所知,父主题在子主题之后第二次初始化它们?我了解继承是如何工作的。我的难题是扩展或使用父主题类。我想在子主题中创建一个新类,该类使用父主题中包含的类进行扩展。但是,当我这样做时,在子主题的functions.php中初始化它。我得到一个错误,说我创建的新类找不到我扩展它的父类。这有意义吗?如何在父主题的子主题中使用类,因为据我所知,父主题在子主题之后第二次初始化它们?