PHP Fatal error: Uncaught Error: Call to undefined method stdClass::save() in error.log

So the complete error is :
PHP Fatal error: Uncaught Error: Call to undefined method stdClass::save() in /var/www/html/ward-suitecrm/custom/include/site_referral_helper.php:29\nStack trace:\n#0 /var/www/html/ward-suitecrm/index.php(57): site_referral_helper->referral_bean_save(’/ward-suitecrm/…’, ‘text/html,appli…’, ‘action=Login&mo…’, 1664882202)\n#1 {main}\n thrown in /var/www/html/ward-suitecrm/custom/include/site_referral_helper.php on line 29

So when I hit the url of website, http 500 error is shown on chrome

hrta_site_referrals.php

public function referral_bean_save($request_uri,$http_accept,$query_string,$request_time)
  {
    $GLOBALS['log']->fatal("Entered in function ");
    $bean = BeanFactory::newBean('hrta_site_referrals'); //new bean method, referal , 
    $bean->server_addr = $this->get_client_ip();
    $bean->url = $request_uri;
    $bean->http_accept = $http_accept;
    $bean->name = $query_string;
    $time = $request_time;
    $bean->request_time = date("Y-m-d H:i:s",$time);
    if(isset($_COOKIE['ck_login_id_20']))
    {
        $bean->assigned_user_id = $_COOKIE['ck_login_id_20'];
        $bean->is_user_loged_in = '1';
    }
    $bean->save();   // GIVES ERROR HERE ! 
  }

index.php:

if(isset($_SERVER['HTTP_SEC_FETCH_MODE'])&&($_SERVER['HTTP_SEC_FETCH_MODE']) == 'navigate'&& !empty($_SERVER['QUERY_STRING']))
{
   require_once 'custom/include/site_referral_helper.php';
   $referral = new site_referral_helper(); 
   $referral->referral_bean_save($_SERVER['REQUEST_URI'],$_SERVER['HTTP_ACCEPT'],$_SERVER['QUERY_STRING'],$_SERVER['REQUEST_TIME']); // GIVES ERROR HERE !
}

If I do global log, its entering into the function hrta_site_referrals.php.
This error only comes when I clone this project and run it without repair and build. If I do repair and build once, then this error goes away permanently!

Please help

Your SuiteCRM version and your PHP version, please…

$suitecrm_version = ‘7.11.10’;
PHP 7.4.20

So the issue was resolved by the help of a senior. The problem was the bean was Null initially. So the save call was not being executed. So we just made an if statement :
if (!empty($bean))
{
execute the code
.
.
$bean->save();
}
So we didn’t made an else statement! Execute the code only when the bean is not empty.

1 Like