这是我的班级财产
private $my_paths = array(
'imagemagick' => 'E:\Server\_ImageOptimize\ImageMagick',
'pngcrush' => 'E:\Server\_ImageOptimize\pngCrush\pngcrush.exe',
'jpegtran' => 'E:\Server\_ImageOptimize\jpegtran\jpegtran.exe',
'gifsicle' => 'E:\Server\_ImageOptimize\gifsicle\gifsicle.exe',
'pngquant' => 'E:\Server\_ImageOptimize\pngquant\pngquant.exe',
'pngout' => 'E:\Server\_ImageOptimize\pngout\pngout.exe'
);
Run Code Online (Sandbox Code Playgroud)
同一个类中有一个静态方法......
public static function is_image($file_path)
{
$imagemagick = $this->my_paths['imagemagick']. '\identify';
echo $imagemagick;
}
Run Code Online (Sandbox Code Playgroud)
当然,这给我带来了错误
Fatal error: Using $this when not in object context...
Run Code Online (Sandbox Code Playgroud)
然后我尝试访问这样的属性,self::my_paths['imagemagick']但这没有帮助.
我该怎么处理?
Mar*_*sen 24
您需要变量/属性名称前面的$符号,因此它变为:
self::$my_paths['imagemagick']
Run Code Online (Sandbox Code Playgroud)
并且my_paths未声明为静态.所以你需要它
private static $my_paths = array(...);
Run Code Online (Sandbox Code Playgroud)
当它前面没有"static"关键字时,它希望在对象中实例化.