Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Amrith's avatar

Class name must be a valid object or a string

Hi Guys, I want to pass $conversationObj via on constructor. but i got this error . could you please help me to resolve this

Error

[2022-04-23 08:24:11] local.ERROR: Class name must be a valid object or a string {"exception":"[object] (Error(code: 0): Class name must be a valid object or a string at closure://function (\BotMan\BotMan\Messages\Incoming\Answer $answer) {
       
     

UserAuthenticateConversation.php

class UserAuthenticateConversation extends Conversation
{

    private $conversationObj;

    public function __construct($conversationObj)
    {
        $this->conversationObj = $conversationObj;

    }

.....
 public function askEmail()
    {
          $this->getBot()->startConversation($this->conversationObj);
    }

DueInvoiceConversation.php

   $dueInvoiceConversation = new DueInvoiceConversation();

   return $this->getBot()->startConversation(new UserAuthenticateConversation($dueInvoiceConversation));
0 likes
4 replies
Amrith's avatar

@jeffallen Confused. could you please explain how could i resolve this ? currently i used constructor based Dependency injection method.

jlrdw's avatar

@Amrith Did you include a use statement at top like example:

<?php
 
namespace App\Http\Controllers;
 
use App\Repositories\UserRepository;    //<----------- Here
 
class UserController extends Controller
{
    /**
     * The user repository instance.
     */
    protected $users;
 
    /**
     * Create a new controller instance.
     *
     * @param  \App\Repositories\UserRepository  $users
     * @return void
     */
    public function __construct(UserRepository $users)
    {
        $this->users = $users;
    }
}
2 likes

Please or to participate in this conversation.