Home >Backend Development >PHP Tutorial >php类文件怎么访问别的文件中的变量

php类文件怎么访问别的文件中的变量

WBOY
WBOYOriginal
2016-06-13 10:26:391188browse

php类文件如何访问别的文件中的变量
我声明了2个文件,一个类文件(123.class.php),一个普通文件(index.php,代码如下),123.class.php中如何获取index.php文件中的$abc的值(在类文件 中直接include不中,获取不到)

123.class.php代码如下:

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?phpinclude ('index.php');class a123{public function index{echo $aa;echo $bb;}}?>


index.php代码:
PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php $aa='aaaaaaaaaaaaaaaaaaaaa';$bb='sdfsdfsdf';?>


实例化代码:

$abc=new a123;
$abc->index();

------解决方案--------------------
include('index.php');
class a123{
public function index{
global $aa, $bb; //或 include('index.php');
echo $aa;
echo $bb;
}
}
------解决方案--------------------
global
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn