Repository navigation
Do not assert a namespace separator when reporting a missing mapping file - #522
Closed
dchaudhari7177 wants to merge 1 commit into
Closed
dchaudhari7177 wants to merge 1 commit into
dchaudhari7177 wants to merge 1 commit into
Conversation
…file
SymfonyFileLocator::findMappingFile() ends by computing the class's short
name for the exception message:
$pos = strrpos($className, '\');
assert(is_int($pos));
A class in the root namespace has no separator, so strrpos() returns false and
the assertion fails. With zend.assertions enabled the caller gets an
AssertionError instead of the MappingException the method is trying to throw:
$locator = new SymfonyFileLocator([]);
$locator->findMappingFile(DateTime::class);
The realistic route in is AbstractQuery::setParameter() with a DateTime value
and no explicit type.
$pos exists only to render the message, so there is nothing to assert. A class
with no separator is its own short name, which is a perfectly good thing to
put in the message.
greg0ire
approved these changes
Sep 10, 2026
greg0ire
requested review from
GromNaN,
SenseException,
beberlei,
derrabus and
stof
September 10, 2026 17:37
Member
|
Hang on… this is a duplicate of #521 |
Member
|
Closing as duplicate. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #520. Targets
3.4.x, since the assertion is on every maintained branch (3.4.x,4.2.x,4.3.x,5.0.x) and merges up.@derrabus's reading in the issue is right:
$posexists only to render the exception message, so there is nothing there to assert.A class in the root namespace has no separator,
strrpos()returnsfalse, and withzend.assertionson the caller gets anAssertionErrorfrom the line that was trying to build aMappingException. So the failure replaces the error you were meant to see with a different one, from one line above it.The special case is that such a class is its own short name —
DateTimeisDateTime— which is a perfectly good thing to name in the message:use function assert;anduse function is_int;go with it; they were only there for that line, andphpcsflags them otherwise.Verified
Red before green, with the production file stashed and the new test left in place:
That is the reported bug reproduced exactly. With the fix:
The new test asserts the message the caller should have been getting all along:
Note
The reproduction in the issue reaches
findMappingFile()forDateTimein the first place, which is arguably its own question — but that path throwsMappingExceptionfor every other class name, and it should for this one too rather than dying one line earlier with a different error class.