这是我的类属性
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'
);在同一个类中有一个静态方法...
public static function is_image($file_path)
{
$imagemagick = $this->my_paths['imagemagick']. '\identify';
echo $imagemagick;
}当然,这会给我一些错误,比如
Fatal error: Using $this when not in object context...然后,我尝试像这样访问该属性的self::my_paths['imagemagick'],但没有任何帮助。
我该怎么处理呢?
发布于 2012-01-09 16:36:06
您需要在变量/属性名前面加上$符号,这样它就变成:
self::$my_paths['imagemagick']并且my_paths没有声明为静态。所以你需要它成为
private static $my_paths = array(...);当它前面没有static关键字时,它希望在对象中被实例化。
发布于 2012-01-09 16:35:29
不能访问静态方法中的非静态属性,应在方法中创建对象的实例或将属性声明为静态。
发布于 2012-01-09 16:38:54
使其成为静态属性
private static $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'
);然后这样叫它
self::$my_paths['pngcrush'];https://stackoverflow.com/questions/8785627
复制相似问题