PHP7→PHP8 업그레이드 오류 나는 부분 체크 정보
PHP PHP7→PHP8 업그레이드 오류 나는 부분 체크본문
PHP7→PHP8 오류나는 부분만 즉시 수정 가이드
? 즉시 수정해야 할 항목만 필터링
1. 치명적 오류 발생 항목
⚠️ each() 함수 제거 - 즉시 수정!
php
// ❌ 오류 발생
while (list($key, $value) = each($array)) { }
// ✅ 수정
foreach ($array as $key => $value) { }
긴급 검색 정규식:
regex
each\s*\(
⚠️ create_function() 제거 - 즉시 수정!
php
// ❌ 오류 발생
$func = create_function('$a, $b', 'return $a + $b;');
// ✅ 수정
$func = function($a, $b) { return $a + $b; };
긴급 검색 정규식:
regex
create_function
2. 정규식 /e 수정자 - 치명적 오류
php
// ❌ 오류 발생
preg_replace('/(.*)/e', 'strtoupper("\\1")', $text);
// ✅ 수정
preg_replace_callback('/(.*)/', function($matches) {
return strtoupper($matches[1]);
}, $text);
긴급 검색 정규식:
regex
/e['"]
3. 필수 매개변수 뒤에 선택 매개변수 - 치명적 오류
php
// ❌ 오류 발생
function test($a = '', $b) {}
// ✅ 수정
function test($b, $a = '') {}
4. 정의되지 않은 배열 키 접근 - 경고 but 즉시 수정
php
// ❌ 경고 발생 echo $_GET['undefined_key']; // ✅ 수정 echo $_GET['undefined_key'] ?? ''; echo isset($_GET['undefined_key']) ? $_GET['undefined_key'] : '';
? 그누보드에서 가장 많이 오류나는 부분
1. 게시판 관련 즉시 수정
php
// ❌ 오류 가능성 높음
if ($wr_id == $write['wr_id']) {}
// ✅ 수정 (형변환 추가)
if (intval($wr_id) == intval($write['wr_id'])) {}
2. 회원 관련 즉시 수정
php
// ❌ 세션 변수 체크 안함
if ($is_member) {}
// ✅ 수정
if (isset($is_member) && $is_member) {}
3. 파일 업로드 즉시 수정
php
// ❌ 파일 존재 안할 때 오류
if ($_FILES['file']['error'] == 0) {}
// ✅ 수정
if (isset($_FILES['file']) && $_FILES['file']['error'] == 0) {}
? 긴급 패치 스크립트
php
<?php
// emergency_php8_fix.php
function emergency_fix($file_path) {
$content = file_get_contents($file_path);
// 1. each() 함수 수정
$content = preg_replace(
'/while\s*\(\s*list\s*\((.*?)\s*\)\s*=\s*each\s*\((.*?)\)\s*\)\s*\{/',
'foreach ($2 as $1) {',
$content
);
// 2. create_function 수정 (간단한 경우만)
$content = preg_replace(
"/create_function\s*\(\s*'([^']+)'\s*,\s*'([^']+)'\s*\)/",
"function(\\1) { \\2 }",
$content
);
file_put_contents($file_path, $content);
}
// 긴급 수정 필요한 파일들
$critical_files = [
'/path/to/gnuboard/lib/common.lib.php',
'/path/to/gnuboard/bbs/board.php',
'/path/to/gnuboard/bbs/write.php',
];
foreach ($critical_files as $file) {
if (file_exists($file)) {
emergency_fix($file);
}
}
?>
? 오류나는 파일만 찾는 검사기
bash
# 터미널에서 실행 - each(), create_function 찾기
grep -r "each\s*(" /path/to/gnuboard/ --include="*.php"
grep -r "create_function" /path/to/gnuboard/ --include="*.php"
grep -r "/e['\"]" /path/to/gnuboard/ --include="*.php"
? 수정 우선순위
-
치명적 오류:
each(),create_function,/e 수정자 -
경고 but 동작: 정의되지 않은 변수, 형변환 문제
-
호환성: 나머지 문제들은 천천히 수정
지금 당장은 1번만 수정해도 대부분 동작합니다!
이렇게 오류나는 부분만 집중해서 수정하면 바로 PHP8에서 동작시킬 수 있습니다.
추천
4
4
댓글 5개

감사합니다.
추천 합니다.

정리해주셔서 감사합니다. ^^

정리 감사합니다.

네 감사합니다.
10년전부터 툴들 많이 나왔으니까 rector 나 php cs fixer 써서 일괄적으로 변경필요한부분 점검하세요