当我说变量时,我并不是指一个常数。
我不是故意的:
class foo {
const BAR = ($_ENV === 'dev') ? 'pages' : 'prod-pages'; // this will fails anyways
public function randomFct () {
echo "BAR"; // of course we can't process a constant in a string
}
}
我的意思是:
class foo {
private $BAR;
public function __construct () {
$this->BAR = ($_ENV === 'dev') ? 'pages' : 'prod-pages';
$this->BAR = 'new'; // throws an error
}
public function randomFct () {
echo "{$this->BAR}";
}
}
编辑:我使用php7.1