Warning: strlen() expects parameter 1 to be string, array given in ○○.php on line △△

エラーメッセージWarning

概要

 状態:-  閲覧数:8,290  投稿日:2014-03-14  更新日:2014-03-14  
・strlen()へ渡すべき引数の数は1つで内容は文字列であるはずなのに、配列を渡したため警告


エラーメッセージ


Warning: strlen() expects parameter 1 to be string, array given in ○○.php on line △△

エラーレベル
・警告

メッセージ
・strlen() expects parameter 1 to be string, array given

ファイル名
・○○.php

行番号
・△△


実際に遭遇した例

 閲覧数:1,006 投稿日:2014-03-14 更新日:2014-03-14 

エラーメッセージ


Warning: strlen() expects parameter 1 to be string, array given in ○○.php on line △△


エラー原因


・ループの中でstrlen()へ配列を渡してしまった
  //全件読み込むループ
while (!feof($file)) {
//1件分のデータを読み込みます
$readdata = fgetcsv($file, 256);
//読み込んだデータを列ごとに出力
if (strlen($readdata) > 0) {
print $readdata[0] . "/" . $readdata[1]. "/" .
$readdata[2] . "/" . $readdata[3]. "<br>";
}
}



対応


・「is_array」で配列のみを渡すよう修正
  //全件読み込むループ
while (!feof($file)) {
//1件分のデータを読込
$readdata = fgetcsv($file, 256);
//読み込んだデータを列ごとに出力
if (is_array($readdata)) {
print $readdata[0] . "/" . $readdata[1]. "/" .
$readdata[2] . "/" . $readdata[3]. "<BR>";
}
}



Warning: array_rand() [function.array-rand]: Second argument has to be between 1

Warning: session_write_close(): Failed to write session data (user)

コメント投稿(ログインが必要)



類似度ページランキング
順位 ページタイトル抜粋
1 Warning: strlen() expects parameter 1 to be string, array given in ○○.php on line △△ 33
2 Warning: htmlspecialchars() expects parameter 1 to be string, array given in ○○.php on line △△ 31
3 ( ! ) Warning: Declaration of xxxx should be compatible with 29
4 SHA-1(Secure Hash Algorithm 1) 28
5 Sorry, that page does not exist. 28
6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in ○○.php on line △△ 28
7 Parse error: syntax error, unexpected $end in ○○.php on line △△ 27
8 Fatal error: Function name must be a string in /○○.php on line △△ 27
9 Parse error: syntax error, unexpected 'public' (T_PUBLIC) 27
10 Warning: Division by zero 26
11 Warning: Missing argument 1 for **(), called in ○○ on line △△ and defined in □□ 26
12 Warning: array_rand() [function.array-rand]: Second argument has to be between 1 26
13 Fatal error: Using $this when not in object context in /○○.php on line △△ 25
14 Warning: mb_convert_encoding(): Unable to detect character encoding 25
15 Parse error: syntax error, unexpected 'new' (T_NEW) 25
16 Parse error: syntax error, unexpected ';', expecting ')' in 25
17 Fatal error: Call-time pass-by-reference has been removed in 25
18 ( ! ) Fatal error: Uncaught Abraham\TwitterOAuth\TwitterOAuthException 25
19 ( ! ) Warning: file_put_contents(/a/b.jpg): failed to open stream: No such file or directory in 25
20 session.gc_maxlifetime 25
2025/10/20 16:37 更新
週間人気ページランキング / 10-13 → 10-19
順位 ページタイトル抜粋 アクセス数
1 register_shutdown_function | 関数処理 関数 5
2 Cookie | クッキー 4
3 Fatal error: Access level to ▲::$△ must be protected (as in class ●) or weaker | Fatal error(エラーメッセージ) 3
4 session.gc_maxlifetime | セッション 2
4 ErrorExceptionクラス | 例外処理(制御構造) 2
4 php-devel とは? 2
4 ( ! ) Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined | Fatal error(エラーメッセージ) 2
4 SQLインジェクション | セキュリティ 2
4 エラー設定(エラーメッセージ) カテゴリー 2
4 ブラウザを閉じたらセッションデータはどうなるの? | セッション 2
4 可変変数 | 変数 2
4 Parse error: syntax error, unexpected 'public' (T_PUBLIC) | Parse error(エラーメッセージ) 2
4 or(||) | 演算子 2
4 Warning: strlen() expects parameter 1 to be string, array given in ○○.php on line △△ | Warning(エラーメッセージ) 2
4 Parse error: syntax error, unexpected T_UNSET in ファイル名 on line 行番号 | Parse error(エラーメッセージ) 2
5 ( ! ) Deprecated: implode(): Passing glue string after array is deprecated. Swap the parameters in ★★★ headless-chromium-php/vendor/wrench/wrench/lib/Wrench/Protocol/Protocol.php | エラーメッセージ 1
5 PHPにおけるメソッドのオーバーライドについて /「引数の数や型は、親クラスのメソッドと完全に一致していなければなりません。」とは具体的にどういう意味ですか? 1
5 クラス | クラスとオブジェクト 1
5 final修飾子 | クラスとオブジェクト 1
5 Fatal error: Uncaught RuntimeException: SplFileObject::__construct(): failed to open stream: Permission denied in | Fatal error(エラーメッセージ) 1
2025/10/20 1:01 更新