empty(func($ var))触发“无法使用函数返回值”错误

时间:2016-12-28 09:26:36

标签: php wordpress

此代码:

import UIKit

extension UIImage {

    /**
     Creates the UIImageJPEGRepresentation out of an UIImage
     @return Data
     */

    func generateJPEGRepresentation() -> Data {

        let newImage = self.copyOriginalImage()
        let newData = UIImageJPEGRepresentation(newImage, 0.75)

        return newData!
    }

    /**
     Copies Original Image which fixes the crash for extracting Data from UIImage
     @return UIImage
     */

    private func copyOriginalImage() -> UIImage {
        UIGraphicsBeginImageContext(self.size);
        self.draw(in: CGRect(x: 0, y: 0, width: self.size.width, height: self.size.height))
        let newImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext();

        return newImage!
    }
}

触发此错误:

  

无法在/home3/*******/public_html/*******/wp-content/themes/outliner/includes/styles.php的写入上下文中使用函数返回值41

我想知道为什么?

1 个答案:

答案 0 :(得分:1)

这里的问题是empty()函数只支持变量。如果你看一下PHP.net Doc for the empty method,你会看到;

  

注意:   在PHP 5.5之前,empty()仅支持变量;其他任何东西都会导致解析错误。换句话说,以下将不起作用:empty(trim($ name))。相反,使用trim($ name)== false。

你需要做类似的事情;

$contentBgImage = get_theme_mod('content_background_image');    
if( get_theme_mod('enable_content_background_color') && empty($contentBgImage ) ) { 
//code
}