Notice: Trying to get property of non-object error

Asked
Active3 hr before
Viewed126 times

7 Answers

objecterrortryingproperty
90%

@Balamanigandan your Original Post :- PHP Notice: Trying to get property of non-object error,Notice: Trying to get property of non-object in **\htdocs\index.php on line 9 + var_dump() returns: NULL,Your are trying to access the Null Object. From AngularJS your are not passing any Objects instead you are passing the $_GET element. Try by using $_GET['uid'] instead of $objData->token, Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers

This is because $pjs is an one-element-array of objects, so first you should access the array element, which is an object and then access its attributes.

echo $pjs[0] - > player_name;
load more v
88%

Just to close the loop here, the session object in template PHP in 2.0 now be:,We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.,Still not sure if that is intended behavior based on reading the docs: http://ellislab.com/expressionengine/user-guide/templates/globals/single_variables.html#var_ip_address,Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.

< ? php
global $SESS;
$uip = $SESS - > userdata['ip_address']; ?
>
load more v
72%

So I’ve set debug to true, and it is throwin me some strange errors that doesn’t appear without it, and is breaking the site.,And of course the error messages are only displayed, if the debug option is turned on. Otherwise they are ignored.,And I pull that json response with file_get_contents() and then json_decode() it, which works fine, and gives me the outputs I want debug = off,Which would output 70 I’ve tried using <?php echo too, still the same error. But as I said, the error is gone when I turn off debug

I’ve got this route

array(
   "pattern" => "api/yt",
   "method" => "GET",
   "action" => function() {
      $api_src = c::get("api.youtube.channel.src").c::get("api.youtube.key");
      $api_src_alt = c::get("api.youtube.channel2.src").c::get("api.youtube.key");

      $api_alt = json_decode(file_get_contents($api_src_alt));
      $api = json_decode(file_get_contents($api_src));

      $views = $api - > items[0] - > statistics - > viewCount + $api_alt - > items[0] - > statistics - > viewCount;
      $videos = $api - > items[0] - > statistics - > videoCount + $api_alt - > items[0] - > statistics - > videoCount;
      $subscribers = $api - > items[0] - > statistics - > subscriberCount + $api_alt - > items[0] - > statistics - > subscriberCount;
      return response::json(array(
         "views" => array(
            "main" => $api - > items[0] - > statistics - > viewCount,
            "services" => $api_alt - > items[0] - > statistics - > viewCount,
            "total" => $api - > items[0] - > statistics - > viewCount + $api_alt - > items[0] - > statistics - > viewCount
         ),
         "videos" => array(
            "main" => $api - > items[0] - > statistics - > videoCount,
            "services" => $api_alt - > items[0] - > statistics - > videoCount,
            "total" => $api - > items[0] - > statistics - > videoCount + $api_alt - > items[0] - > statistics - > videoCount
         ),
         "subscribers" => array(
            "main" => $api - > items[0] - > statistics - > subscriberCount,
            "services" => $api_alt - > items[0] - > statistics - > subscriberCount,
            "total" => $api - > items[0] - > statistics - > subscriberCount + $api_alt - > items[0] - > statistics - > subscriberCount
         )
      ));
   }
),

which gives me this json response as I want
debug = off

{
   "views": {
      "main": "37519",
      "services": "7163",
      "total": 44682
   },
   "videos": {
      "main": "48",
      "services": "22",
      "total": 70
   },
   "subscribers": {
      "main": "184",
      "services": "35",
      "total": 219
   }
}

And I pull that json response with file_get_contents() and then json_decode() it, which works fine, and gives me the outputs I want
debug = off

$api = json_decode(file_get_contents($site - > url().
   "/api/yt"));
echo $api - > views - > total; //44682
echo $api - > videos - > total; //70

but when I turn on debug mode, I get this
debug = on

Notice: Trying to get property of non - object in /Volumes/TheWiseGrey / WebServer / gsponsor.dev / site / templates / home.php on line 35
load more v
65%

Error Trying to get property of non-object in C ... ,94284/error-trying-get-property-non-object-wamp-www-pages-init-php, Web Development (1,457) ,Full Stack Web Developer Masters Program

Here is my Control page:

< ? php
include 'pages/db.php';
$results = mysql_query("SELECT * FROM sidemenu WHERE `menu_id`='".$menu.
   "' ORDER BY `id` ASC LIMIT 1", $con);
$sidemenus = mysql_fetch_object($results); ?
>

on View Page:

<?php foreach ($sidemenus as $sidemenu): ?>
<?php echo $sidemenu->mname."<br />";?>
<?php endforeach; ?>

Error is:

Notice: Trying to get property of non - object in C: \wamp\ www\ ni\ pages\ init.php on line 22
load more v
75%

 

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

Code:

<?php

$sql = "SELECT 
    Form_Group
    COUNT(Presence LIKE '/') AS Present,
    COUNT(Presence LIKE 'N') AS Absent,
FROM 'attendance'";
$result = $conn->query($sql);

?>

<?php
//Fetch Data form database
if($result->num_rows > 0){
while($row = $result->fetch_rows()){
?>


<tr>
<td><?php echo $row['Form_Group']; ?></td>
<td><?php echo $row['Present']; ?></td>
<td><?php echo $row['Absent']; ?></td>
</tr>

<?php
}
}
else
{
?>
<tr>
<th colspan="6">There's No data found!!!</th>
</tr>
<?php
}
?>
load more v
40%

You can use isset() or property_exists() to check if the property exists., Yes you should post as a new question. Before, go to that line and use another isset() before using that array variable. It should be fixed. – RRikesh Feb 27 '13 at 10:40 , Help Center Detailed answers to any questions you might have , Questions

You can use isset() or property_exists() to check if the property exists.

foreach($taxonomies_password_terms_obj as $taxonomy) {
   if (isset($taxonomy - > term_id)) {
      $options_password_taxonomies[$taxonomy - > term_id] = $taxonomy - > name;
   }
}
22%

I’m trying to echo out the name of the user in my article and I’m getting the ErrorException: Trying to get property of non-object. My codes:,When I try to remove name in the blade {{ $article->postedBy }} it outputs the id, but when I try to add the ->name there it says Trying to get property of non-object but I have a field name in my table and a User model. Am I missing something?,Is your query returning array or object? If you dump it out, you might find that it’s an array and all you need is an array access ([]) instead of an object access (->).,Next is to add a second parameter in my belongsTo, from

Problem

I’m trying to echo out the name of the user in my article and I’m getting the ErrorException: Trying to get property of non-object. My codes:

ErrorException: Trying to get property of non - object
load more v

Other "object-error" queries related to "Notice: Trying to get property of non-object error"