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

Sindo's avatar
Level 2

Object of class stdClass could not be converted to string

Hey all - I've been looking into this problem for a while now and don't know what to think of it.

I'm calling a SOAP API server with this command: $arr_agenda = $this->connection->GetAgendaItems($GetAgenda);

GetAgenda is an object with this content

$GetAgenda = new GetAgenda(); $GetAgenda->UserName = $this->UserName; $GetAgenda->Password = $this->Password; $GetAgenda->AgendaFilter = $AgendaFilter;

AgendaFilter is a second object with this content:

App\Ets\Classes\AgendaFilter { +LastModifiedTimeGreaterOrEqualThan: null +StartGreaterOrEqualThan: "2019-10-28 00:00:00" +EndSmallerOrEqualThan: null +EmployeesId: null }

When I run the code I get an error

ErrorException Object of class stdClass could not be converted to string https://gmt.test/update/syncAgenda

Illuminate\Foundation\Bootstrap\HandleExceptions::handleError vendor/monolog/monolog/src/Monolog/Formatter/LineFormatter.php:184

When I leave out the AgendaFilter everything runs fine.

The GetAgendaItems method expects this:

GetAgendaItems (string UserName, string Password, AgendaFilter AgendaFilter)

AgendaFilter is this: LastModifiedTimeGreaterOrEqualThan Nullable - DateTime StartGreaterOrEqualThan - Nullable DateTime EndSmallerOrEqualThan - Nullable DateTime EmployeesId - List

Any guidance on where to look would be very much appreciated.

0 likes
7 replies
bugsysha's avatar

It can be a lot of things. Maybe somewhere you are doing (string) $classObject, or you are returning an $classObject but you have return type defined on that method :string, or concatenating $classObject to a string, or passing an $classObject where string is expected. Using proper IDE maybe can give you better insight into your error.

Sindo's avatar
Level 2

Hi Bugsysha - thank you for your answer.

The system returns "Object of class stdClass could not be converted to string" So my guess is that the object returned from AgendaFilter should be a string, but GetAgendaItems (string UserName, string Password, AgendaFilter AgendaFilter) would suggest that to not be the case?

Or am I missing something?

bugsysha's avatar

Nope. AgendaFilter in this example is not being returned but passed as an argument. Or am I missing something?

Sindo's avatar
Level 2

Maybe this will help.

$dt = Carbon::createMidnightDate(date('Y'), date('m'), date('d'))->subMonths(6);

$AgendaFilter = new AgendaFilter();

$AgendaFilter->StartGreaterOrEqualThan = $dt->toDateTimeString();

$GetAgenda = new GetAgenda();

$GetAgenda->UserName = $this->UserName;

$GetAgenda->Password = $this->Password;

$GetAgenda->AgendaFilter = $AgendaFilter;

$arr_agenda = $this->connection->GetAgendaItems($GetAgenda);

bugsysha's avatar

Try

$arr_agenda = $this->connection->GetAgendaItems($this->UserName, $this->Password, $AgendaFilter);
Sindo's avatar
Level 2

Same thing :(

I'll just leave out the filter for now and dig into it later.

Thanks for the help! Appreciated!

Please or to participate in this conversation.