當我嘗試運行腳本時,即使在全局範圍內定義腳本,我的ONE,TWO和THREE變量也未定義。我的A,B和C變量被認爲是定義的。起初我認爲這是因爲我將常量值分配爲鍵,但是我沒有在網上找到任何說我無法做到的事情。變量未定義,即使在聲明後
<?php class aClass
{
const A = 1;
const B = 2;
const C = 3;
const ONE = 1;
const TWO = 2;
const THREE = 3;
public $arr = [];
function __construct() {
$this->createArray();
}
function createArray() {
$this->arr[] = $this->A = [
$this->ONE => 'one.',
$this->TWO => 'two',
$this->THREE => 'three'
];
$this->arr[] = $this->B = [
$this->ONE => 'one',
$this->TWO => 'two',
$this->THREE => 'three',
];
$this->arr[] = $this->C = [
$this->ONE => 'one',
$this->TWO => 'two',
$this->THREE => 'three',
];
}
}
?>
什麼是你想用這個來完成?你可以在'createArray()'運行後包含一個你希望'$ this-> arr'的例子嗎? –