아파치 2.2.14에서 CodeIgniter 2.0과 PHP5.3.2를 MySQL 5.1.48-community에서 사용하고 있습니다. 나는 다른 문제를 격리하기 위해 작은 테스트 컨트롤러를 만들었고 내 문제는 공공 변수 접근성 때문에 발생하는 것으로 나타났습니다. test1 또는 test2를 호출하면 다른 함수에 설정된 배열 요소의 값을 볼 수 없으므로 오류가 발생합니다. 아무도 왜 이것이 작동하지 않는지 알 수 있습니까? 그렇다면 클래스 전체 변수에 액세스 할 수 있어야하는 이유는 무엇입니까?클래스 함수에서 PHP5 클래스의 공용 변수 값에 액세스 할 수없는 이유는 무엇입니까?
감사합니다.
<?php
class Test extends CI_Controller
{
public $data;
function __construct()
{
parent::__construct();
$this->data = array();
}
function index()
{
$this->data['test1'] = 'This is a test of class public variable access.<br />';
echo 'Class index() called.<br />';
echo $this->data['test1'];
}
function test1()
{
$this->data['test2'] = 'This is a second test of the class public variable access.<br />';
echo 'Class test1 called.<br />';
echo $this->data['test1'];
echo $this->data['test2'];
}
function test2()
{
echo 'The data array contains these two entries:<br />';
echo $this->data['test1'];
echo $this->data['test2'];
}
}
/* End of file test.php*/
/* Location: */
이 순서와 순서는 무엇이며 출력은 무엇입니까? – deceze
오류 메시지의 정확한 표현은 무엇입니까? – Unsigned
이 코드를 보지 못했습니다 ... CI_Controller 및 오류 메시지 세부 정보가 필요합니다. –