LeftJoin with FQDN as join generates TypeError #6797

Closed
opened 2026-01-22 15:38:50 +01:00 by admin · 2 comments
Owner

Originally created by @rrajkomar on GitHub (Aug 3, 2021).

Bug Report

Q A
BC Break unknown
Version 2.10.x

Summary

Using the \Doctrine\ORM\QueryBuilder::leftJoin method with a FQDN as first parameter causes a type error on the first instruction.
Assuming all namespaces imports and all classes are correctly defined and loaded, a call looking like the following:

[...]
->leftJoin(Account::class, [...])
[...]

will trigger a type error on :

$parentAlias = substr($join, 0, strpos($join, '.'));

Current behavior

This error is triggered :
Type error: substr() expects parameter 3 to be int, bool given

How to reproduce

Simple use a leftJoin with a FQDN class as the first parameter

Expected behavior

The join should work without issues

Fix

The call should include a typecast to int just as it was done on the innerJoin method.

$parentAlias = substr($join, 0, (int) strpos($join, '.'));
Originally created by @rrajkomar on GitHub (Aug 3, 2021). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | unknown | Version | 2.10.x #### Summary Using the \Doctrine\ORM\QueryBuilder::leftJoin method with a FQDN as first parameter causes a type error on the first instruction. Assuming all namespaces imports and all classes are correctly defined and loaded, a call looking like the following: ```php [...] ->leftJoin(Account::class, [...]) [...] ``` will trigger a type error on : ```php $parentAlias = substr($join, 0, strpos($join, '.')); ``` #### Current behavior This error is triggered : Type error: substr() expects parameter 3 to be int, bool given #### How to reproduce Simple use a leftJoin with a FQDN class as the first parameter #### Expected behavior The join should work without issues #### Fix The call should include a typecast to int just as it was done on the innerJoin method. ```php $parentAlias = substr($join, 0, (int) strpos($join, '.')); ```
admin closed this issue 2026-01-22 15:38:50 +01:00
Author
Owner

@dunglas commented on GitHub (Sep 29, 2021):

It looks like a PHP bug to me. According to the documentation:

If length is given and is 0, false or null, an empty string will be returned.

(emphasis mine)

@dunglas commented on GitHub (Sep 29, 2021): It looks like a PHP bug to me. According to the documentation: > If length is given and is 0, **false** or null, an empty string will be returned. (emphasis mine)
Author
Owner

@drealecs commented on GitHub (Sep 30, 2021):

The documentation needs to be improved.
Also, the documentation is correct if strict types are off as false is coerced to 0.
When strict types are on, you must respect the method signature and either pass an int or null.
Your fix is correct and where it needs to be. strict_types where enabled in 2.10.x and 3.0.x and this is a change that must go with that. Unfortunately there were not enough tests to catch it initially.

@drealecs commented on GitHub (Sep 30, 2021): The documentation needs to be improved. Also, the documentation is correct if strict types are off as `false` is coerced to `0`. When strict types are on, you must respect the method signature and either pass an `int` or `null`. Your fix is correct and where it needs to be. `strict_types` where enabled in 2.10.x and 3.0.x and this is a change that must go with that. Unfortunately there were not enough tests to catch it initially.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6797