出现这个错误信息的原因是在静态方法中使用$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        '<li>';
            echo             '<select name="row_area_id" class="w-200 row_area_id">';
            echo                   '<option value="">-暂未开放-</option>';
            echo              '</select>';
            echo                   '<input type="text" name="row_area_address" class="w-300">';
            echo              '</li>';
        }
    }
    
    public static function areaPlace($city_id, $area_id, $address){
        echo        '<li>';
        echo             '<select name="row_area_id" class="w-200 row_area_id">';
        $this->areaSelect($city_id, $area_id);
        echo              '</select>';
        echo                   '<input type="text" name="row_area_address" class="w-300" value="'.$address.'">';
        echo              '</li>';
    }红色代码处应改为:
self::areaPlace($city_id, $place['area_id'], $place['address']); $this->areaSelect($city_id, $area_id);
以上就介绍了Using $this when not in object context错误信息,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
                        
                        每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
                Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号