IT

PHP에서 경고 잘못된 문자열 오프셋을 수정하는 방법

itgroup 2023. 3. 4. 14:45
반응형

PHP에서 경고 잘못된 문자열 오프셋을 수정하는 방법

PHP 코드의 청크가 있어, 에러가 발생하고 있습니다.

경고:C:\xampp\htdocs\Manta\wp-content\temes\manta\functions의 문자열 오프셋 'iso_format_recent_works'가 잘못되었습니다.1328행의 php

경고와 관련된 코드는 다음과 같습니다.

if(1 == $manta_option['iso_format_recent_works']){
    $theme_img = 'recent_works_thumbnail';
} else {
    $theme_img = 'recent_works_iso_thumbnail';
}

내가 할 때var_dump($manta_option);다음과 같은 결과를 받았습니다.

["iso_format_module_works"]=> 문자열 (1) "1"

캐스팅을 해봤습니다.$manta_option['iso_format_recent_works']에 대해서int하지만 여전히 같은 문제가 발생합니다.

어떤 도움이라도 주시면 감사하겠습니다!

마법의 단어는: 이셋

엔트리의 유효성을 확인합니다.

if(isset($manta_option['iso_format_recent_works']) && $manta_option['iso_format_recent_works'] == 1){
    $theme_img = 'recent_works_thumbnail';
} else {
    $theme_img = 'recent_works_iso_thumbnail';
}

1.

 if(1 == @$manta_option['iso_format_recent_works']){
      $theme_img = 'recent_works_thumbnail';
 } else {
      $theme_img = 'recent_works_iso_thumbnail';
 }

2.

if(isset($manta_option['iso_format_recent_works']) && 1 == $manta_option['iso_format_recent_works']){
    $theme_img = 'recent_works_thumbnail';
} else {
    $theme_img = 'recent_works_iso_thumbnail';
}

3.

if (!empty($manta_option['iso_format_recent_works']) && $manta_option['iso_format_recent_works'] == 1){
}
else{
}

단순히 액세스만 시도하는 것이 아니라 어레이에 키가 존재하는지 확인하십시오.

대체:

$myVar = $someArray['someKey']

예를 들어 다음과 같습니다.

if (isset($someArray['someKey'])) {
    $myVar = $someArray['someKey']
}

예를 들어 다음과 같습니다.

if(is_array($someArray['someKey'])) {
    $theme_img = 'recent_works_iso_thumbnail';
}else {
    $theme_img = 'recent_works_iso_thumbnail';
}

언급URL : https://stackoverflow.com/questions/22279230/how-to-fix-warning-illegal-string-offset-in-php

반응형