我无法理解如何使用对象.
具体代码:
class first{
class second{
public function widgets(){
$a_variable = $a_value;
}
#1
}
$second = new second;
#2
}
#3
$first = new first;
>如果我将$a_variable初始化为$a_variable,它只在函数内可用,对吗?
>如果我将$a_varialbe初始化为$this-> a_variable,它只在第二级内可用,对吗?
>我可以将$a_variable初始化为$first-> second-> a_variable?如果是这样,我怎么称它为#1,#2和#3?
>我可以将$a_varialbe初始化为$this-> second-> a_variable?如果是这样,我怎么称它为#1,#2和#3?
正如您所看到的,我对OOP如何工作感到困惑.
首先,我想表达我多么感谢所有的帮助.我已经学到了足够多的东西来认为这个问题取得了巨大的成功.
也就是说,即使它的配方很差,伪代码和无效的语法,这个代码也会运行.
class class_1{
public function function_1(){
require('class_2.php');
public function function_2_callback(){
//%%%%%% How do I set a variable here and get the DATA...
}
$this->class_2 = new class_2("function_2_callback");
}
}
$class_1 = new class_1;
//&&&&&&&&&& Get the DATA here?
/* CONTENTS OF class_2.php */
class class_2($callback){
call_user_function($callback);
}
即使我们不得不将此视为一种练习.有人可以告诉我如何首先设置(@ %%%%%%%)然后调用变量(@&&&&&&&&&)如图所示?