Skip to content

Commit 3ef9c6c

Browse files
minor #35945 Leverage PHP8's get_debug_type() (nicolas-grekas)
This PR was merged into the 5.1-dev branch. Discussion ---------- Leverage PHP8's get_debug_type() | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - See symfony/polyfill#226 for background. We might have to port part of the patch to 4.4 when we'll work on having it support PHP 8, but that's not needed for now. Commits ------- daf1c6605e Leverage PHP8's get_debug_type()
2 parents 204076f + 8a2d306 commit 3ef9c6c

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

LazyString.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class LazyString implements \Stringable, \JsonSerializable
2828
public static function fromCallable($callback, ...$arguments): self
2929
{
3030
if (!\is_callable($callback) && !(\is_array($callback) && isset($callback[0]) && $callback[0] instanceof \Closure && 2 >= \count($callback))) {
31-
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a callable or a [Closure, method] lazy-callable, "%s" given.', __METHOD__, \gettype($callback)));
31+
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a callable or a [Closure, method] lazy-callable, "%s" given.', __METHOD__, get_debug_type($callback)));
3232
}
3333

3434
$lazyString = new static();
@@ -57,7 +57,7 @@ public static function fromCallable($callback, ...$arguments): self
5757
public static function fromStringable($value): self
5858
{
5959
if (!self::isStringable($value)) {
60-
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a scalar or a stringable object, "%s" given.', __METHOD__, \is_object($value) ? \get_class($value) : \gettype($value)));
60+
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a scalar or a stringable object, "%s" given.', __METHOD__, get_debug_type($value)));
6161
}
6262

6363
if (\is_object($value)) {
@@ -143,7 +143,7 @@ private static function getPrettyName(callable $callback): string
143143
}
144144

145145
if (\is_array($callback)) {
146-
$class = \is_object($callback[0]) ? \get_class($callback[0]) : $callback[0];
146+
$class = \is_object($callback[0]) ? get_debug_type($callback[0]) : $callback[0];
147147
$method = $callback[1];
148148
} elseif ($callback instanceof \Closure) {
149149
$r = new \ReflectionFunction($callback);
@@ -155,14 +155,10 @@ private static function getPrettyName(callable $callback): string
155155
$class = $class->name;
156156
$method = $r->name;
157157
} else {
158-
$class = \get_class($callback);
158+
$class = get_debug_type($callback);
159159
$method = '__invoke';
160160
}
161161

162-
if (isset($class[15]) && "\0" === $class[15] && 0 === strpos($class, "class@anonymous\x00")) {
163-
$class = (get_parent_class($class) ?: key(class_implements($class))).'@anonymous';
164-
}
165-
166162
return $class.'::'.$method;
167163
}
168164
}

0 commit comments

Comments
 (0)