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

Puankare's avatar

PHP Parse error: Unexpected character "" (ASCII 26)

Hi! I am pretty new to Laravel. I have this error which I couldn't fix...

When I run App\Models\User::factory()->create(), I get this error:

PARSE ERROR PHP Parse error: Unexpected character "" (ASCII 26) in vendor\psy\psysh\src\Exception\ParseErrorException.php on line 44.

This is my UserFactory.php


namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
 */
class UserFactory extends Factory
{
    /**
     * The current password being used by the factory.
     */
    protected static ?string $password;

    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            'first_name' => fake()->firstName(),
            'last_name' => fake()->lastName(),
            'email' => fake()->unique()->safeEmail(),
            'email_verified_at' => now(),
            'password' => static::$password ??= Hash::make('password'),
            'remember_token' => Str::random(10),
        ];
    }

    /**
     * Indicate that the model's email address should be unverified.
     */
    public function unverified(): static
    {
        return $this->state(fn (array $attributes) => [
            'email_verified_at' => null,
        ]);
    }
}

and User.php


namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
    use HasFactory, Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'first_name',
        'last_name',
        'email',
        'password',
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array<int, string>
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'email_verified_at' => 'datetime',
            'password' => 'hashed',
            'is_admin' => 'boolean',
        ];
    }
}
0 likes
7 replies
Talinon's avatar

@puankare

When I run App\Models\User::factory()->create(), I get this error

How are you running it? In a test? invoking a script? using tinker?

If you're running it in tinker, be sure to reload (exit and re-enter tinker) because changes to the code won't take immediate effect in tinker's memory. You could update the code all day long and still get the same error.

If you're running it in a test, or other means, pasting the full error stack message here may help.

Puankare's avatar

Sorry, I forgot to mention that: I run it through tinker, and yes, I exit and reload tinker. And the weird thing is, another factory, below, is working just fine:

<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Release>
 */
class ReleaseFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            'version_name' => fake()->firstName(),
            'summary' => fake()->text(),
        ];
    }
}
JussiMannisto's avatar

That ascii code is an invisible control character. It may have gotten there if you copy-pasted the code from somewhere.

Check the full error message to see id you can locate where thr character is. IDEs usually show control characters as visible blocks.

Puankare's avatar

I use vscode, with prettier - I don't know if I need any special extension to make control characters visible? I copied the code to notepad and back, both for usefactory.php and user.php, exit tinker, rerun - still the same error.

JussiMannisto's avatar
Level 50

@Puankare Did you read the full error message and the stack trace?

Copy-pasting doesn't remove characters.

Edit. To see the stack trace in tinker, type wtf -a after you get the error. The invalid character might also be in your tinker input.

1 like
Puankare's avatar

@JussiMannisto wtf -a produced:

 0:  () at vendor\psy\psysh\src\Exception\ParseErrorException.php:44
 1:  Psy\Exception\ParseErrorException::fromParseError() at vendor\psy\psysh\src\CodeCleaner.php:333
 2:  Psy\CodeCleaner->parse() at vendor\psy\psysh\src\CodeCleaner.php:262
 3:  Psy\CodeCleaner->clean() at vendor\psy\psysh\src\Shell.php:848
 4:  Psy\Shell->addCode() at vendor\psy\psysh\src\Shell.php:535
 5:  Psy\Shell->getInput() at vendor\psy\psysh\src\ExecutionLoopClosure.php:37
 6:  Psy\{closure}() at vendor\psy\psysh\src\ExecutionClosure.php:89
 7:  Psy\ExecutionClosure->execute() at vendor\psy\psysh\src\Shell.php:383
 8:  Psy\Shell->doInteractiveRun() at vendor\psy\psysh\src\Shell.php:354
 9:  Psy\Shell->doRun() at vendor\symfony\console\Application.php:167
10:  Symfony\Component\Console\Application->run() at vendor\psy\psysh\src\Shell.php:329
11:  Psy\Shell->run() at vendor\laravel\tinker\src\Console\TinkerCommand.php:85
12:  Laravel\Tinker\Console\TinkerCommand->handle() at vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:36
13:  Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() at vendor\laravel\framework\src\Illuminate\Container\Util.php:41
14:  Illuminate\Container\Util::unwrapIfClosure() at vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:93
15:  Illuminate\Container\BoundMethod::callBoundMethod() at vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:35
16:  Illuminate\Container\BoundMethod::call() at vendor\laravel\framework\src\Illuminate\Container\Container.php:662
17:  Illuminate\Container\Container->call() at vendor\laravel\framework\src\Illuminate\Console\Command.php:213
18:  Illuminate\Console\Command->execute() at vendor\symfony\console\Command\Command.php:279
19:  Symfony\Component\Console\Command\Command->run() at vendor\laravel\framework\src\Illuminate\Console\Command.php:182
20:  Illuminate\Console\Command->run() at vendor\symfony\console\Application.php:1047
21:  Symfony\Component\Console\Application->doRunCommand() at vendor\symfony\console\Application.php:316
22:  Symfony\Component\Console\Application->doRun() at vendor\symfony\console\Application.php:167
23:  Symfony\Component\Console\Application->run() at vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php:196
24:  Illuminate\Foundation\Console\Kernel->handle() at vendor\laravel\framework\src\Illuminate\Foundation\Application.php:1198
25:  Illuminate\Foundation\Application->handleCommand() at artisan:13
Puankare's avatar

@JussiMannisto That was it!!! When I retyped App\Models\User::factory()->create() from scratch, it worked. Thank you very much!

Please or to participate in this conversation.