这是我的课堂财产
- 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...
然后我尝试访问这样的属性:: my_paths [‘imagemagick’],但没有帮助.
我该如何处理?
您需要在变量/属性名前面的$符号,所以它变成:
- self::$my_paths['imagemagick']
而my_paths没有声明为静态.所以你需要它
- private static $my_paths = array(...);
当它的前面没有“static”关键字时,它期望在一个对象中实例化.