我正在制作一个带有 OOP 概念的 WordPress 插件,但我面临一些有线问题。
首先我有一个main-plugin.php
文件,我有这样的课程
include_once plugin_dir_path( __FILE__ ) . 'something.php';
class something {
//some var
public $a;
private function __construct() { {
//all of my wordpress hook calls are here
}
public function foo() {
$this->a = 55; // this is working fine and not giving any error
}
}
现在我有另一个 php 文件,其中包含我包含在的另一个类main-plugin.php
file
假设新文件是something.php
我在这里有
class some {
//some variables
public $b, $c;
// now this this class when I'm doming
public function bar() {
$this->b =1; // this is giving me error saying this is not an object.
}
}
现在我不知道为什么$this
不在 else 类中工作。另外由于这些变量不是静态变量,我真的不能这样做self::$b
。所以,我希望其他人能告诉我一种在不使用类的情况下访问类内非静态变量的方法$this
.
我想,你一定有这样的例子AICP_ADMIN
in https://github.com/isaumya/adsense-invalid-click-protector/blob/master/adsense-invalid-click-protector.php#L91 https://github.com/isaumya/adsense-invalid-click-protector/blob/master/adsense-invalid-click-protector.php#L91而不是字符串。所以尝试类似的东西
$aicpAdmin = new AICP_ADMIN;
add_action( 'admin_enqueue_scripts', array( $aicpAdmin, 'admin_scripts' ) );
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)