Skip to content

Conversation

@axlon
Copy link
Contributor

@axlon axlon commented Dec 17, 2025

The query builder returns query results as instances of stdClass, however currently it is documented as if it can return any object. This PR narrows the type to more accurately reflect what is being returned. This doesn't affect calling code, editors, etc. but it does change something for PHPStan.

PHPStan has a special list of classes on which it assumes any property can exist, it calls this universal object crates, stdClass is one of these classes, this means that:

Before:

$result = $query->find($id); // <- object|null

if (is_null($result)) {
    return;
}

echo "Hello, $result->first_name"; // <- PHPStan error, first_name might not exist on 'object'

After:

$result = $query->find($id); // <- stdClass|null

if (is_null($result)) {
    return;
}

echo "Hello, $result->first_name"; // <- OK

Relevant PHPStan docs: https://phpstan.org/config-reference#universal-object-crates

Note: Some query builder methods (get, cursor) already use stdClass

@axlon
Copy link
Contributor Author

axlon commented Dec 17, 2025

Failing test seems unrelated (this PR only changes docs)

@taylorotwell taylorotwell merged commit 735778d into laravel:12.x Dec 17, 2025
70 of 72 checks passed
iam-subho pushed a commit to iam-subho/laravel-core that referenced this pull request Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants