如果它显示错误为“试图获取非对象的属性”,如何识别哪个是代码中的非对象?

After making some modifications to my existing script, I created an error:

Notice: Trying to get property of non-object...

I am trying to figure how to identify if the variable $result is an object so I don't get this error (I am getting the error on this particular line if ($result-> num_rows > 0) { ). Here is what have:

<?php 
$sql = "SELECT * FROM input WHERE id =".$_GET["id"]; 
$result = mysqli_query ($conn,$sql);

if ($result-> num_rows > 0) { 
    while($row -> $result->fetch_assoc()) { 
        $myid = $row["id"] ;
        $sql2 = "SELECT * FROM output WHERE question_id = $myid ORDER BY date DESC";
        $result2 = $conn->query($sql2);
        $sql3 = "SELECT COUNT(*) as rowCount FROM output WHERE question_id = '".$myid."'";

        $result3 = $conn->query($sql3);
        $rowCount= $result3->fetch_assoc();
?>

How can I tell beforehand if this is an object or not?

First of all, do you have the variable $conn initialized any where in the code before that?
Second, you want to make your while loop like this:
while($row = $result->fetch_assoc()) { ... }

You can use to find content is array or object :

is_object() to find object 
is_array() to find array 

$sql = "SELECT * FROM compt WHERE id =1"; 
$result = mysqli_query ($conn,$sql);

if ($result->num_rows > 0) { 
    while($row = $result->fetch_assoc()) { 

    }
    }