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

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

WBOY
Release: 2016-06-13 13:28:28
Original
983 people have browsed it

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/

-->
<?php include('index.php');
class a123{
public function index{

echo $aa;
echo $bb;

}

}
?>

Copy after login


index.php代码:
PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php $aa='aaaaaaaaaaaaaaaaaaaaa';
$bb='sdfsdfsdf';
?>

Copy after login


实例化代码:

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

------解决方案--------------------
include('index.php');
class a123{
public function index{
global $aa, $bb; //或 include('index.php');
echo $aa;
echo $bb;
}
}
------解决方案--------------------
global
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template