개발! 딱 깔끔하고 센스있게!

구문 분석 오류 : 유효하지 않은 숫자 리터럴 본문

개발 스크랩 메모/PHP

구문 분석 오류 : 유효하지 않은 숫자 리터럴

렉사이 2020. 11. 20. 17:03

다음 코드를 실행할 때 다음 오류가 발생합니다:

코드:

 

오류:

Parse error: Invalid numeric literal.

왜 이 문제가 생겼는지 어떻게 해결해야 합니까?

대답

php7 에서 정수 처리 (특히 팔진수) 방식의 변경 (opsoed to php5) 에서 나온 것이다.

문서 (php7 이전)

Invalid octal literals

Previously, octal literals that contained invalid numbers were silently truncated (0128 was taken as 012). Now, an invalid octal literal will cause a parse error.

전체 문서에서

Prior to PHP 7, if an invalid digit was given in an octal integer (i.e. 8 or 9), the rest of the number was ignored. Since PHP 7, a parse error is emitted.

혹은 문자열 또는 실제 정수

$a = array(1, 8, 9, 12); // Integers $a = array("00001", "00008", "00009", "00012"); // Strings 
Comments