{"id":6169,"date":"2024-07-23T12:39:22","date_gmt":"2024-07-23T03:39:22","guid":{"rendered":"https:\/\/taitan916.info\/blog\/?p=6169"},"modified":"2024-07-23T13:02:12","modified_gmt":"2024-07-23T04:02:12","slug":"post-6169","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/6169","title":{"rendered":"PHP8\u7cfb\u3067\u300cUncaught TypeError: count(): Argument\u300d\u30a8\u30e9\u30fc\u306e\u5bfe\u5fdc\u65b9\u6cd5"},"content":{"rendered":"<p>PHP8\u7cfb\u3067\u300cPHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in\u300d\u3068\u3044\u3046\u30a8\u30e9\u30fc\u30ed\u30b0\u304c\u898b\u53d7\u3051\u3089\u308c\u305f\u30027\u7cfb\u3060\u3068\u554f\u984c\u7121\u304f\u52d5\u3044\u3066\u3044\u305f\u30da\u30fc\u30b8\u3060\u3063\u305f\u304cPHP8\u7cfb\u3060\u3068Fatal error\u306b\u306a\u308a\u52d5\u4f5c\u3057\u306a\u304f\u306a\u3063\u305f\u3002\u4ee5\u4e0b\u306b\u539f\u56e0\u3068\u5bfe\u5fdc\u65b9\u6cd5\u3092\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u539f\u56e0<\/h2>\n<p><a href=\"https:\/\/www.php.net\/manual\/ja\/function.count.php\" target=\"_blank\" rel=\"noopener\">count\u95a2\u6570<\/a>\u3092\u4f7f\u7528\u3059\u308b\u969b\u306b\u5f15\u6570\u304cNULL\u306b\u306a\u3063\u3066\u3044\u305f\u305f\u3081\u767a\u751f\u3057\u305f\u6a21\u69d8\u3002<\/p>\n<p>\u5177\u4f53\u7684\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306e\u5834\u5408\u306b\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?php\r\nini_set( 'display_errors', 1 );\r\n$hoge = NULL;\r\nif( count($hoge) ){\r\n    echo 1;\r\n}else{\r\n    echo 0;\r\n}<\/pre>\n<p>\u3061\u306a\u307f\u306bPHP7\u3067\u4e0a\u8a18\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068Fatal error\u3067\u306f\u306a\u304f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306aWarning\u30a8\u30e9\u30fc\u3068\u306a\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Warning: count(): Parameter must be an array or an object that implements Countable in \/path\/to\/file.php on line xxxx<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u5bfe\u5fdc\u65b9\u6cd5<\/h2>\n<h3>\u5f15\u6570\u3092\u5b9a\u7fa9<\/h3>\n<p>\u5f15\u6570\u3092\u5b9a\u7fa9\u3059\u308b\u3002\u6050\u3089\u304f\u4e00\u756a\u7121\u96e3\u304b\u3068\u601d\u308f\u308c\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">$hoge = array();<\/pre>\n<h3>\u5f15\u6570\u3092\u30ad\u30e3\u30b9\u30c8<\/h3>\n<p>count\u6642\u306b\u5f15\u6570\u3092(array)\u3067\u30ad\u30e3\u30b9\u30c8\u3059\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">if( count((array)$hoge) ){<\/pre>\n<h3>\u5f15\u6570\u304c\u6570\u3048\u3089\u308c\u308b\u5024\u304b\u3069\u3046\u304b\u3092\u8abf\u3079\u308b<\/h3>\n<p><a href=\"https:\/\/www.php.net\/manual\/ja\/function.is-countable.php\" target=\"_blank\" rel=\"noopener\">is_countable\u95a2\u6570<\/a>\u3092\u4f7f\u7528\u3057\u5f15\u6570\u304c\u6570\u3048\u3089\u308c\u308b\u5024\u304b\u3069\u3046\u304b\u8abf\u3079\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">if( is_countable($hoge) &amp;&amp; count($hoge) ){<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u6240\u611f<\/h2>\n<p>\u3053\u3061\u3089\u306e\u30b5\u30a4\u30c8\u306b\u3088\u308b\u3068<a href=\"https:\/\/fanblogs.jp\/scripts\/archive\/100\/0\" target=\"_blank\" rel=\"noopener\">PHP8\u7cfb\u304b\u3089\u306fNULL\u3092\u8a31\u5bb9\u3057\u306a\u3044\u95a2\u6570\u304c\u5897\u3048\u305f<\/a>\u3068\u306e\u3053\u3068\u3002<\/p>\n<p>\u307e\u305f\u3001<a href=\"https:\/\/qiita.com\/rana_kualu\/items\/7f84fcea5c70248ac99e\" target=\"_blank\" rel=\"noopener\">PHP9\u7cfb\u304b\u3089\u306f\u672a\u5b9a\u7fa9\u5909\u6570\u304c\u4f7f\u3048\u306a\u304f\u306a\u308b<\/a>\u3068\u3044\u3046\u8a71\u306a\u306e\u3067\u3001\u4eca\u5f8c\u306f\u5909\u6570\u3092\u4f7f\u3046\u5834\u5408\u306f\u304d\u3061\u3093\u3068\u5b9a\u7fa9\u3059\u308b\u3088\u3046\u6c17\u3092\u3064\u3051\u305f\u3044\u3068\u3053\u308d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP8\u7cfb\u3067\u300cPHP Fatal error: Uncaught TypeErr ... <\/p>\n","protected":false},"author":1,"featured_media":1085,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-6169","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6169","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/comments?post=6169"}],"version-history":[{"count":2,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6169\/revisions"}],"predecessor-version":[{"id":6171,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6169\/revisions\/6171"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media\/1085"}],"wp:attachment":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media?parent=6169"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=6169"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=6169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}