반응형
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
반응형
'IT' 카테고리의 다른 글
wordpress 위젯에서_content()를 자르는 데 subst()가 작동하지 않습니다. (0) | 2023.03.04 |
---|---|
API를 사용하지 않고 MailChimp 관심 그룹 ID를 얻을 수 있습니까? (0) | 2023.03.04 |
mongodb 컬렉션에 중복 문서 삽입을 중지하는 방법 (0) | 2023.03.04 |
중첩된 JSON 개체 - 모든 작업에 어레이를 사용해야 합니까? (0) | 2023.03.04 |
리액트로 에이잭스 처리 (0) | 2023.03.04 |