欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

Using $this when not in object context错误信息

程序员文章站 2022-06-03 16:13:50
...
出现这个错误信息的原因是在静态方法中使用$this来调用本类的方法,在php中,静态方法调用使用self。代码如下
    public static function editPlaceSelect($places=[], $city_id=-1){
        if(is_array($places) && count($places)>0){
            foreach ($places as $place){
                $this->areaPlace($city_id, $place['area_id'], $place['address']);
            }
        }else{
            echo        '
  • '; echo ''; echo ''; echo '
  • '; } } public static function areaPlace($city_id, $area_id, $address){ echo '
  • '; echo ''; echo ''; echo '
  • '; }

    红色代码处应改为

    self::areaPlace($city_id, $place['area_id'], $place['address']);
    
    $this->areaSelect($city_id, $area_id);

    以上就介绍了Using $this when not in object context错误信息,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。