[SOLVED] Notice: Trying to get property 'currentdate' of non-object in C:\xampp\htdocs\test\clearance.php


Here’s the code
I’m trying to echo the data from the clearance form table if the $today date matches with the $expirydate from the clearance table

$today = date("Y-m-d");
$expirydate = $row->currentdate; //from database

$today_time = strtotime($today);
$expire_time = strtotime($expirydate);

if ($expire_time < $today_time) {
    echo '(body....) ';


The arrow -> is also called the object operator and is used to access properties or non-static methods on an object of a class.

You should debug your code to check the type of $row because it obviously is not an object that has an property currentdate. Because of this the error you got was thrown.

As a bonus tip you should also check out the null-safe operator which checks for null

Quote from https://wiki.php.net/rfc/nullsafe_operator:

When the left hand side of the operator evaluates to null the
execution of the entire chain will stop and evalute to null. When it
is not null it will behave exactly like the normal -> operator.

Answered By – WebDevPassion

Answer Checked By – David Marino (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *