'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....) ';


Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wai Ha Lee