PHP 5.3 ~ PHP7 - 정의되지 않은 클래스 상수 'self::MYCONST' (PHP 5.3 to PHP7 - Undefined class constant 'self::MYCONST')


문제 설명

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 ShermanRuslan Lenkov)

참조 문서

  1. PHP 5.3 to PHP7 ‑ Undefined class constant 'self::MYCONST' (CC BY‑SA 2.5/3.0/4.0)

#PHP #class-constants #migration #php-7






관련 질문

bash의 rsync가 php 생성 --exclude-from 파일을 구문 분석하지 않음 (rsync in bash not parsing php-generated --exclude-from file)

PHP 배열 값 저장 (PHP Save array value)

검색으로 배열에서 특정 데이터 가져오기 (get specific datas from a array by a search)

창 서비스를 사용하여 PHP 파일 트리거 (Trigger a php file using window service)

yii2 컨트롤러 작업 주입은 어떻게 작동합니까? (How does the yii2 Controller action injection works)

php와 drupal을 사용하여 pdf를 텍스트로 변환 (pdf to text convert using php and drupal)

PHP에서 카테고리 및 하위 카테고리 목록 검색 (Retrieve Category & Subcategory list in PHP)

PDO - COUNT(*) 결과를 얻습니까? (PDO - get the result of a COUNT(*)?)

PHP - MySQL 쿼리 문제 (PHP - Mysql query problem)

제품용 Reviews.io API의 Foreach 루프 (Foreach loop in Reviews.io API for Products)

숫자를 나누고 점 뒤에 하나의 숫자를 유지하십시오. (Split the number and keep one number after the dot)

내 메시지 입력이 데이터베이스에 들어가지 않습니다. (My message input doesn't get into database)







코멘트