我声明了2个文件,一个类文件(123.class.php),一个普通文件(index.php,代码如下),123.class.php中如何获取index.php文件中的$abc的值(在类文件 中直接include不中,获取不到)123.class.php代码如下:<?php
include('index.php');
class a123{
public function index{echo $aa;
echo $bb;}}
?>
index.php代码:<?php
$aa='aaaaaaaaaaaaaaaaaaaaa';
$bb='sdfsdfsdf';
?>
实例化代码:$abc=new a123;
$abc->index();
include('index.php');
class a123{
public function index{echo $aa;
echo $bb;}}
?>
index.php代码:<?php
$aa='aaaaaaaaaaaaaaaaaaaaa';
$bb='sdfsdfsdf';
?>
实例化代码:$abc=new a123;
$abc->index();
class a123{
public function index(){
include('index.php');
echo $aa;
echo $bb;}}
class a123{
public function index{
global $aa, $bb; //或 include('index.php');
echo $aa;
echo $bb;
}
}
include(dirname(__FILE__)."/index.php");