Skip to content

Commit

Permalink
Represent simple strings that happen to be callable as strings (#1734)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfb committed May 18, 2024
1 parent d12ed37 commit 4dc0a9a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Serializer/AbstractSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ protected function serializeCallable($callable): string
throw new \InvalidArgumentException(sprintf('Expecting callable, got %s', \is_object($callable) ? \get_class($callable) : \gettype($callable)));
}

// Prefer a string representation for simple strings that might just
// happen to be callable, such as "file".
if (\is_string($callable) && strpos($callable, '::') === false && strpos($callable, '_') === false) {
return $this->serializeString($callable);
}

try {
if (\is_array($callable)) {
$reflection = new \ReflectionMethod($callable[0], $callable[1]);
Expand Down

0 comments on commit 4dc0a9a

Please sign in to comment.