I have the following code, perform a global function within a class to fill the functions of wordpress, the problem is that the only way that I could get a variable public class is as follows
class Core {
public $notice;
function __construct(){
$this->core_function();
}
function core_function(){
global $globalvar;
$globalvar = $this;
function notice_global(){
global $globalvar;
return $globalvar->notice;
}
}
function set_notice(){
$this->notice = array('Warning');
}
}
$GP = new Core();
$GP->set_notice();
var_dump(notice_global());
Any other ideas or suggestions, this code is correct or not?
var_dupm()doesn't exists.$GP->notice? It's a public variable.$GP->noticeand delete__construnc,core_functionandnotice_global. There is a particular reason to callnotice_global()instead of$GP->noticenotice_global()inside functioncore_function(). PHP should raise a strict error. PHP will treat it as a normal method! So what you have coded is wrong in PHP. However, because you have used theglobal $globalvar;, which is such a wrong thing to be doing, the code will work correctly! ;-/