【发布时间】:2017-08-25 15:52:29
【问题描述】:
在我的 Apache ErrorLog 文件中,我多次看到此警告消息:
[2017 年 8 月 23 日星期三 17:27:25.146025] [:error] [pid 14989] [client 66.249.76.54:44935] PHP 警告:isset 中的偏移量类型非法或 /var/www/html/blog/ 中为空wp-content/plugins/ilab-media-tools/classes/tools/s3/ilab-media-s3-tool.php 在第 1012 行
它与一个 Wordpress 插件有关,我尝试使用 Github 向作者(和其他许多人一样)寻求帮助,但没有。
警告指向这个函数:
public function imageDownsize($fail,$id,$size) {
if (apply_filters('ilab_imgix_enabled', false)) {
return $fail;
}
$meta=wp_get_attachment_metadata($id);
// This is the line of the warning:
if (!isset($meta['sizes']) || !isset($meta['sizes'][$size])) {
return $fail;
}
$sizeMeta = $meta['sizes'][$size];
if (!isset($sizeMeta['s3'])) {
return $fail;
}
$url = $sizeMeta['s3']['url'];
$result=[
$url,
$sizeMeta['width'],
$sizeMeta['height'],
true
];
return $result;
}
Apache 每分钟打印一次此警告。 有没有办法解决这个烦人的消息警告?
这是var_dump($meta);的输出:
array(7) {
["width"]=>
int(140)
["height"]=>
int(140)
["file"]=>
string(31) "2016/01/logo_retina.png"
["sizes"]=>
array(0) {
}
["image_meta"]=>
array(12) {
["aperture"]=>
int(0)
["credit"]=>
string(0) ""
["camera"]=>
string(0) ""
["caption"]=>
string(0) ""
["created_timestamp"]=>
int(0)
["copyright"]=>
string(0) ""
["focal_length"]=>
int(0)
["iso"]=>
int(0)
["shutter_speed"]=>
int(0)
["title"]=>
string(0) ""
["orientation"]=>
int(0)
["keywords"]=>
array(0) {
}
}
["ewww_image_optimizer"]=>
string(30) "Reduced by 16.3% (1.3 kB)"
["s3"]=>
array(3) {
["url"]=>
string(79) "https://s3-eu-west-1.amazonaws.com/blog-example/2016/01/logo_retina.png"
["bucket"]=>
string(12) "blog-example"
["key"]=>
string(31) "2016/01/logo_retina.png"
}
}
array(7) {
["width"]=>
int(140)
["height"]=>
int(140)
["file"]=>
string(31) "2016/01/logo_retina.png"
["sizes"]=>
array(0) {
}
["image_meta"]=>
array(12) {
["aperture"]=>
int(0)
["credit"]=>
string(0) ""
["camera"]=>
string(0) ""
["caption"]=>
string(0) ""
["created_timestamp"]=>
int(0)
["copyright"]=>
string(0) ""
["focal_length"]=>
int(0)
["iso"]=>
int(0)
["shutter_speed"]=>
int(0)
["title"]=>
string(0) ""
["orientation"]=>
int(0)
["keywords"]=>
array(0) {
}
}
["ewww_image_optimizer"]=>
string(30) "Reduced by 16.3% (1.3 kB)"
["s3"]=>
array(3) {
["url"]=>
string(79) "https://s3-eu-west-1.amazonaws.com/blog-example/2016/01/logo_retina.png"
["bucket"]=>
string(12) "blog-example"
["key"]=>
string(31) "2016/01/logo_retina.png"
}
}
array(7) {
["width"]=>
int(140)
["height"]=>
int(140)
["file"]=>
string(31) "2016/01/logo_retina.png"
["sizes"]=>
array(0) {
}
["image_meta"]=>
array(12) {
["aperture"]=>
int(0)
["credit"]=>
string(0) ""
["camera"]=>
string(0) ""
["caption"]=>
string(0) ""
["created_timestamp"]=>
int(0)
["copyright"]=>
string(0) ""
["focal_length"]=>
int(0)
["iso"]=>
int(0)
["shutter_speed"]=>
int(0)
["title"]=>
string(0) ""
["orientation"]=>
int(0)
["keywords"]=>
array(0) {
}
}
["ewww_image_optimizer"]=>
string(30) "Reduced by 16.3% (1.3 kB)"
["s3"]=>
array(3) {
["url"]=>
string(79) "https://s3-eu-west-1.amazonaws.com/blog-example/2016/01/logo_retina.png"
["bucket"]=>
string(12) "blog-example"
["key"]=>
string(31) "2016/01/logo_retina.png"
}
}
array(7) {
["width"]=>
int(140)
["height"]=>
int(140)
["file"]=>
string(31) "2016/01/logo_retina.png"
["sizes"]=>
array(0) {
}
["image_meta"]=>
array(12) {
["aperture"]=>
int(0)
["credit"]=>
string(0) ""
["camera"]=>
string(0) ""
["caption"]=>
string(0) ""
["created_timestamp"]=>
int(0)
["copyright"]=>
string(0) ""
["focal_length"]=>
int(0)
["iso"]=>
int(0)
["shutter_speed"]=>
int(0)
["title"]=>
string(0) ""
["orientation"]=>
int(0)
["keywords"]=>
array(0) {
}
}
["ewww_image_optimizer"]=>
string(30) "Reduced by 16.3% (1.3 kB)"
["s3"]=>
array(3) {
["url"]=>
string(79) "https://s3-eu-west-1.amazonaws.com/blog-example/2016/01/logo_retina.png"
["bucket"]=>
string(12) "blog-example"
["key"]=>
string(31) "2016/01/logo_retina.png"
}
}
array(7) {
["width"]=>
int(140)
["height"]=>
int(140)
["file"]=>
string(31) "2016/01/logo_retina.png"
["sizes"]=>
array(0) {
}
["image_meta"]=>
array(12) {
["aperture"]=>
int(0)
["credit"]=>
string(0) ""
["camera"]=>
string(0) ""
["caption"]=>
string(0) ""
["created_timestamp"]=>
int(0)
["copyright"]=>
string(0) ""
["focal_length"]=>
int(0)
["iso"]=>
int(0)
["shutter_speed"]=>
int(0)
["title"]=>
string(0) ""
["orientation"]=>
int(0)
["keywords"]=>
array(0) {
}
}
["ewww_image_optimizer"]=>
string(30) "Reduced by 16.3% (1.3 kB)"
["s3"]=>
array(3) {
["url"]=>
string(79) "https://s3-eu-west-1.amazonaws.com/blog-example/2016/01/logo_retina.png"
["bucket"]=>
string(12) "blog-example"
["key"]=>
string(31) "2016/01/logo_retina.png"
}
}
还有var_dump($size);的输出:
string(4) "full"
array(2) {
[0]=>
int(32)
[1]=>
int(32)
}
array(2) {
[0]=>
int(192)
[1]=>
int(192)
}
array(2) {
[0]=>
int(180)
[1]=>
int(180)
}
array(2) {
[0]=>
int(270)
[1]=>
int(270)
}
【问题讨论】:
-
你确定
$meta是一个数组吗? -
你可以添加这一行,它应该可以工作
if(count($meta["sizes"]) < $size) return $fail; -
把这一行放在下面
$meta=wp_get_attachment_metadata($id); -
很高兴帮助@NineCattoRules...我也会在 github 上进行修复和拉取请求。
-
根据你的
var_dump,$size是一个数组,导致偏移错误。此外,if(count($meta["sizes"]) < $size) return $fail;在不满足 if 条件时仍会返回错误。你应该检查你传递给函数的$size。