문제 설명
PHP 5.3 ~ PHP7 ‑ 정의되지 않은 클래스 상수 'self::MYCONST' (PHP 5.3 to PHP7 ‑ Undefined class constant 'self::MYCONST')
PHP 7.0으로 마이그레이션하려는 PHP 5.3.21에서 실행 중인 프로젝트가 있습니다. 프로젝트는 아래 예와 같이 많은 구조를 사용합니다.
<?php
class foo {
protected $_const = self::MYCONST;
}
class boo extends foo {
const MYCONST = "test";
public function __construct() {
echo $this‑>_const.PHP_EOL;
}
}
new boo();
예상 결과는 "test"를 인쇄하는 것이며 5.3에서는 완벽하게 작동하지만 7.0에서는
PHP 치명적인 오류: 잡히지 않은 오류: 정의되지 않은 클래스 상수 'self::MYCONST'
어떤 도움이라도 주시면 감사하겠습니다.
참조 솔루션
방법 1:
Try to transfer the constants to the parent classes in your project
(by Sherman、Ruslan Lenkov)