严格的标准:不应该静态调用非静态方法,假设$ php来自php文件中不兼容的上下文

时间:2016-01-21 01:06:22

标签: java php android json

我对PHP有基本的了解,我在从PHP Web服务中检索JSON对象时遇到错误

constructor(points: Point[], name?: string);
constructor(walls: Wall[], name?: string);
constructor(pointsOrWalls: (Wall | Point)[], name?: string) {
    if (pointsOrWalls[0] instanceof Point) {
        //  If first is Point all must be Points

        //  But here typescript says that pointsOrWalls is of type (Wall | Point)[]
        this.walls = pointsOrWalls.map(function(point, ind, points) {
            return new Wall(point, points[++ind % points.length])
        })
    }else{
        //  Since these aren't points they are Walls
        this.walls = walls
    }
    this.name = name
}

因此,由于此错误,我无法正确解析我的JSON对象并在我的Android Studio logcat中出现此错误

Strict standards: Non-static method API_USERS::getRecordByID() should not be called statically, assuming $this from incompatible context in .../lists.php on line 1387

有没有办法摆脱这个错误?这是我试图使用的PHP:

Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject

这是我认为是错误来源的代码(第1387行)

  <?php
    define('IEM_PATH', '../admin/com');
    require_once('../admin/includes/config.php');
    require_once('../admin/com/lib/IEM.class.php');
    require_once ('../admin/com/lib/IEM/DBFACTORY.class.php');
    require_once ('../admin/com/lib/IEM/baseAPI.class.php');
    require_once ('../admin/com/lib/API/USERS.class.php');
    require_once ('../admin/com/lib/IEM/baseRecord.class.php');
    require_once ('../admin/com/lib/record/Users.class.php');

        function GetLists($userid = 0, $getUnconfirmedCount = false) {

            $userid = $_REQUEST['userID'];
            if (!$userid) {
                trigger_error('This user object is not loaded with any user.... You will need to supply the userid as a parameter.', E_USER_NOTICE);
                return false;
            }


            if (!$userid) {
                $userid = $this->userid;
            }

            require_once('../admin/functions/api/lists.php');

            $listapi = new Lists_API();
            $returnA =  $listapi->GetListByUserID($userid, $getUnconfirmedCount);
            $returnResult1 = array();
            foreach ($returnA as $key => $value) { 
                //$lists[] = $key;
                $returnResult["contactList"][] = array("listID" => $returnA[$key]['listid'], "name" => $returnA[$key]['name']);
            }
            $returnResult["success"] = 1;
            echo json_encode($returnResult);
        }

        GetLists();

1 个答案:

答案 0 :(得分:0)

此代码是从类中复制的:

$userid = $this->userid;

当你不在(非静态)成员函数中时,你没有$ this。

删除这3行:

    if (!$userid) {
        $userid = $this->userid;
    }