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

cutups's avatar

Events: preg_match(): Argument #2 ($subject) must be of type string

Running into an odd error that started recently after updating some packages, but it's not clear what caused it.

In my code, I have an event (laravel) that is dispatched after an Event (my object) is created.

EventCreated::dispatch($event);

Now I'm getting an error such as:

preg_match(): Argument #2 ($subject) must be of type string

[https://imgur.com/a/Q9SkN96]

However, there is no second parameter for dispatching.

Below is the EventCreated code for reference.

<?php

namespace App\Events;

use App\Models\Event;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class EventCreated implements ShouldBroadcast
{
    use Dispatchable;
    use InteractsWithSockets;
    use SerializesModels;

    public Event $event;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct(Event $event)
    {
        $this->event = $event;
        $this->dontBroadcastToCurrentUser();
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return Channel|array
     */
    public function broadcastOn()
    {
        return new Channel('events');
    }
}
0 likes
2 replies
Niush's avatar
Niush
Best Answer
Level 50

In the error page click "Expand vendor frames" and click the top most stack, to see where the error is coming from. It might explain more. May be composer dependencies did not update successfully.

cutups's avatar

@Niush Thanks Niush - that helped. The error ended up being inside of pusher:

    private function validate_socket_id($socket_id)

    {

        if ($socket_id !== null && !preg_match('/\A\d+\.\d+\z/', $socket_id)) {

            throw new PusherException('Invalid socket ID '.$socket_id);

        }

    }

After upgrading pusher-php-server from v4.1.5 to 7.0.2 things worked.

1 like

Please or to participate in this conversation.