我是PHP OOP概念中的新人。第一件引起我注意的事情是,我不能在脚本开始时写一次php脚本给多个类。我的意思是PHP仅包含外部类一次
<?php
include 'var.php';
class userSession{
/* all the code */
public function getVariables(){
/* use of variables which are inside var.php */
}
public function getOtherVariables(){
/* use of variables which are inside var.php */
}
}
?>
这是行不通的。
我不得不这样做 -
<?php
class userSession{
/* all the code */
public function getVariables(){
include 'var.php';
/* use of variables which are inside var.php */
}
public function getOtherVariables(){
include 'var.php';
/* use of variables which are inside var.php */
}
}
?>
什么我失踪?
var.php的内容是什么。 – 2010-08-08 11:13:50
在第一个示例中,您将var.php的内容包含在全局空间中。 在第二个示例中,您将var.php的内容包含在您类的方法的本地空间中。 你究竟想在这里做什么? – 2010-08-08 11:15:19
假设只有两个变量。 '<?php $ var1 =“hello”; $ VAR2 = “世界”; ?> – 2010-08-08 11:15:39