Skip to content

Depricated use of null as array offset in php8.5 #208

@victorhjelmbergcego

Description

@victorhjelmbergcego

https://www.php.net/manual/en/migration85.deprecated.php
"Using null as an array offset or when calling array_key_exists() is now deprecated. Instead an empty string should be used."

This is caused when doing eager loading with single key that is null

class A extends Model
{
    use Compoships;
    
    public function b(): HasMany
    {
        return $this->hasMany(B::class, 'c', 'c');
    }
}

#[Test]
public function bug_reproduction(): void
{
	A::factory()->create(['c' => null]);
	A::query()->with(['b'])->get();
}

The deprication happens in Database/Eloquent/Relations/HasOneOrMany.php where dictKey will be null, which causes array null offset on line 240 in the following

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions