mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-04 04:07:39 +02:00
Fix Utils::getClass() with PHP8 (#1563)
This commit is contained in:
committed by
GitHub
parent
42384f29ba
commit
63e195046c
@@ -19,7 +19,15 @@ final class Utils
|
|||||||
{
|
{
|
||||||
$class = \get_class($object);
|
$class = \get_class($object);
|
||||||
|
|
||||||
return 'c' === $class[0] && 0 === strpos($class, "class@anonymous\0") ? get_parent_class($class).'@anonymous' : $class;
|
if (false === ($pos = \strpos($class, "@anonymous\0"))) {
|
||||||
|
return $class;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (false === ($parent = \get_parent_class($class))) {
|
||||||
|
return \substr($class, 0, $pos + 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $parent . '@anonymous';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function substr(string $string, int $start, ?int $length = null): string
|
public static function substr(string $string, int $start, ?int $length = null): string
|
||||||
|
@@ -13,6 +13,25 @@ namespace Monolog;
|
|||||||
|
|
||||||
class UtilsTest extends \PHPUnit_Framework_TestCase
|
class UtilsTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param string $expected
|
||||||
|
* @param object $object
|
||||||
|
* @dataProvider provideObjects
|
||||||
|
*/
|
||||||
|
public function testGetClass($expected, $object)
|
||||||
|
{
|
||||||
|
$this->assertSame($expected, Utils::getClass($object));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideObjects()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['stdClass', new \stdClass()],
|
||||||
|
['class@anonymous', new class {}],
|
||||||
|
['stdClass@anonymous', new class extends \stdClass {}],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $expected
|
* @param string $expected
|
||||||
* @param string $input
|
* @param string $input
|
||||||
|
Reference in New Issue
Block a user