I have the following function in the php script,
public function createPorductstatushistory($item) {
$stmt = mysqli_prepare($this->connection, "INSERT INTO $this->tablename (timeStamp, ProductDetail_idProduct, ProductStatus_idStatus) VALUES (?, ?, ?)");
$this->throwExceptionOnError();
mysqli_stmt_bind_param
($stmt, 'sii',
$item->timeStamp->toString('YYYY-MM-dd HH:mm:ss'),
$item->ProductDetail_idProduct,
$item->ProductStatus_idStatus);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$autoid = mysqli_stmt_insert_id($stmt);
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $autoid;
}
but, everytime I go to the part “$item->timeStamp->toString(‘YYYY-MM-dd HH:mm:ss’)”. The following error pop up.
There was an error while invoking the operation. Check your operation
inputs or server code and try invoking the operation again.Reason: Notice: Trying to get property of non-object in
C:\xampp\htdocs\fypweee_admin\FYPadminSideV3-debug\services\PorductstatushistoryService.php
on line 125Fatal error: Call to a member function toString() on a non-object in
C:\xampp\htdocs\fypweee_admin\FYPadminSideV3-debug\services\PorductstatushistoryService.php
on line 125
Is this mean the timeStamp var need to be in format of ‘YYYY-MM-dd HH:mm:ss’?
Your
$itemobject has a propertytimeStamp. You assume that thetimeStampproperty of$itemis an object. But the error tells you thattimeStampis not an object.This could mean that you never set an instance of an object to
timeStamp.Example:
This would result in such an error. You need to initialize
TimeStampand assign that to your$timeStampvariable.Now this should work, because
TimeStampis initialized in the constructor and assigned to the$timeStampvariable.So please recheck your code and make sure everything you need is instantiated