diff --git a/build/kint.phar b/build/kint.phar
index fd8b89e67..ad12ad5fc 100644
Binary files a/build/kint.phar and b/build/kint.phar differ
diff --git a/src/Parser/Parser.php b/src/Parser/Parser.php
index 2d971bc37..5c7a40a3a 100644
--- a/src/Parser/Parser.php
+++ b/src/Parser/Parser.php
@@ -407,6 +407,10 @@ private function parseObject(&$var, Value $o): Value
$object->spl_object_hash = $hash;
$object->size = \count($values);
+ if (KINT_PHP72) {
+ $object->spl_object_id = \spl_object_id($var);
+ }
+
if (isset($this->object_hashes[$hash])) {
$object->hints[] = 'recursion';
diff --git a/src/Renderer/Rich/AbstractPlugin.php b/src/Renderer/Rich/AbstractPlugin.php
index e8b9fe51a..4d9ec7067 100644
--- a/src/Renderer/Rich/AbstractPlugin.php
+++ b/src/Renderer/Rich/AbstractPlugin.php
@@ -28,6 +28,7 @@
namespace Kint\Renderer\Rich;
use Kint\Renderer\RichRenderer;
+use Kint\Zval\InstanceValue;
use Kint\Zval\Value;
/**
@@ -42,6 +43,9 @@ public function __construct(RichRenderer $r)
$this->renderer = $r;
}
+ /**
+ * @param string $content The replacement for the getValueShort contents
+ */
public function renderLockedHeader(Value $o, string $content): string
{
$header = '
';
@@ -65,17 +69,28 @@ public function renderLockedHeader(Value $o, string $content): string
}
if (null !== ($s = $o->getType())) {
- $s = $this->renderer->escape($s);
+ if (RichRenderer::$escape_types) {
+ $s = $this->renderer->escape($s);
+ }
if ($o->reference) {
$s = '&'.$s;
}
- $header .= ''.$s.' ';
+ $header .= ''.$s.'';
+
+ if ($o instanceof InstanceValue && isset($o->spl_object_id)) {
+ $header .= '#'.((int) $o->spl_object_id);
+ }
+
+ $header .= ' ';
}
if (null !== ($s = $o->getSize())) {
- $header .= '('.$this->renderer->escape($s).') ';
+ if (RichRenderer::$escape_types) {
+ $s = $this->renderer->escape($s);
+ }
+ $header .= '('.$s.') ';
}
$header .= $content;
diff --git a/src/Renderer/Rich/CallablePlugin.php b/src/Renderer/Rich/CallablePlugin.php
index 4caee4d6a..043c2110d 100644
--- a/src/Renderer/Rich/CallablePlugin.php
+++ b/src/Renderer/Rich/CallablePlugin.php
@@ -37,65 +37,28 @@ class CallablePlugin extends AbstractPlugin implements ValuePluginInterface
{
protected static $method_cache = [];
- public function renderValue(Value $o): string
+ protected $closure_plugin = null;
+
+ public function renderValue(Value $o): ?string
{
if ($o instanceof MethodValue) {
return $this->renderMethod($o);
}
if ($o instanceof ClosureValue) {
- return $this->renderClosure($o);
- }
-
- return $this->renderCallable($o);
- }
-
- protected function renderClosure(ClosureValue $o): string
- {
- $children = $this->renderer->renderChildren($o);
-
- $header = '';
-
- if (null !== ($s = $o->getModifiers())) {
- $header .= ''.$s.' ';
- }
-
- if (null !== ($s = $o->getName())) {
- $header .= ''.$this->renderer->escape($s).'('.$this->renderer->escape($o->getParams()).')';
- }
-
- if (null !== ($s = $o->getValueShort())) {
- if (RichRenderer::$strlen_max) {
- $s = Utils::truncateString($s, RichRenderer::$strlen_max);
- }
- $header .= ' '.$this->renderer->escape($s);
+ return $this->getClosurePlugin()->renderValue($o);
}
- return ''.$this->renderer->renderHeaderWrapper($o, (bool) \strlen($children), $header).$children.'
';
+ return null;
}
- protected function renderCallable(Value $o): string
+ protected function getClosurePlugin(): ClosurePlugin
{
- $children = $this->renderer->renderChildren($o);
-
- $header = '';
-
- if (null !== ($s = $o->getModifiers())) {
- $header .= ''.$s.' ';
- }
-
- if (null !== ($s = $o->getName())) {
- $header .= ''.$this->renderer->escape($s).'';
- }
-
- if (null !== ($s = $o->getValueShort())) {
- if (RichRenderer::$strlen_max) {
- $s = Utils::truncateString($s, RichRenderer::$strlen_max);
- }
- $header .= ' '.$this->renderer->escape($s);
+ if (null === $this->closure_plugin) {
+ $this->closure_plugin = new ClosurePlugin($this->renderer);
}
- return ''.$this->renderer->renderHeaderWrapper($o, (bool) \strlen($children), $header).$children.'
';
+ return $this->closure_plugin;
}
protected function renderMethod(MethodValue $o): string
diff --git a/src/Renderer/Rich/ClosurePlugin.php b/src/Renderer/Rich/ClosurePlugin.php
index cea043743..a2b5a7e06 100644
--- a/src/Renderer/Rich/ClosurePlugin.php
+++ b/src/Renderer/Rich/ClosurePlugin.php
@@ -33,26 +33,29 @@
class ClosurePlugin extends AbstractPlugin implements ValuePluginInterface
{
- public function renderValue(Value $o): string
+ public function renderValue(Value $o): ?string
{
+ if (!$o instanceof ClosureValue) {
+ return null;
+ }
+
$children = $this->renderer->renderChildren($o);
- if (!($o instanceof ClosureValue)) {
- $header = $this->renderer->renderHeader($o);
- } else {
- $header = '';
+ $header = '';
- if (null !== ($s = $o->getModifiers())) {
- $header .= ''.$s.' ';
- }
+ if (null !== ($s = $o->getModifiers())) {
+ $header .= ''.$s.' ';
+ }
- if (null !== ($s = $o->getName())) {
- $header .= ''.$this->renderer->escape($s).'('.$this->renderer->escape($o->getParams()).') ';
- }
+ if (null !== ($s = $o->getName())) {
+ $header .= ''.$this->renderer->escape($s).'('.$this->renderer->escape($o->getParams()).') ';
+ }
- $header .= 'Closure ';
- $header .= $this->renderer->escape(Kint::shortenPath($o->filename)).':'.(int) $o->startline;
+ $header .= 'Closure';
+ if (isset($o->spl_object_id)) {
+ $header .= '#'.((int) $o->spl_object_id);
}
+ $header .= ' '.$this->renderer->escape(Kint::shortenPath($o->filename)).':'.(int) $o->startline;
$header = $this->renderer->renderHeaderWrapper($o, (bool) \strlen($children), $header);
diff --git a/src/Renderer/Rich/SimpleXMLElementPlugin.php b/src/Renderer/Rich/SimpleXMLElementPlugin.php
deleted file mode 100644
index ae29999aa..000000000
--- a/src/Renderer/Rich/SimpleXMLElementPlugin.php
+++ /dev/null
@@ -1,79 +0,0 @@
-renderer->renderChildren($o);
-
- $header = '';
-
- if (null !== ($s = $o->getModifiers())) {
- $header .= ''.$s.' ';
- }
-
- if (null !== ($s = $o->getName())) {
- $header .= ''.$this->renderer->escape($s).' ';
-
- if ($s = $o->getOperator()) {
- $header .= $this->renderer->escape($s, 'ASCII').' ';
- }
- }
-
- if (null !== ($s = $o->getType())) {
- $s = $this->renderer->escape($s);
-
- if ($o->reference) {
- $s = '&'.$s;
- }
-
- $header .= ''.$this->renderer->escape($s).' ';
- }
-
- if (null !== ($s = $o->getSize())) {
- $header .= '('.$this->renderer->escape($s).') ';
- }
-
- if (null !== ($s = $o->getValueShort())) {
- if (RichRenderer::$strlen_max) {
- $s = Utils::truncateString($s, RichRenderer::$strlen_max);
- }
- $header .= $this->renderer->escape($s);
- }
-
- $header = $this->renderer->renderHeaderWrapper($o, (bool) \strlen($children), $header);
-
- return ''.$header.$children.'
';
- }
-}
diff --git a/src/Renderer/RichRenderer.php b/src/Renderer/RichRenderer.php
index fb29e276e..4ef045f46 100644
--- a/src/Renderer/RichRenderer.php
+++ b/src/Renderer/RichRenderer.php
@@ -56,7 +56,6 @@ class RichRenderer extends AbstractRenderer
'color' => Rich\ColorPlugin::class,
'depth_limit' => Rich\DepthLimitPlugin::class,
'recursion' => Rich\RecursionPlugin::class,
- 'simplexml_element' => Rich\SimpleXMLElementPlugin::class,
'trace_frame' => Rich\TraceFramePlugin::class,
];
@@ -312,7 +311,13 @@ public function renderHeader(Value $o): string
$s = '&'.$s;
}
- $output .= ''.$s.' ';
+ $output .= ''.$s.'';
+
+ if ($o instanceof InstanceValue && isset($o->spl_object_id)) {
+ $output .= '#'.((int) $o->spl_object_id);
+ }
+
+ $output .= ' ';
}
if (null !== ($s = $o->getSize())) {
diff --git a/src/Renderer/TextRenderer.php b/src/Renderer/TextRenderer.php
index 58f327ca1..833320a6c 100644
--- a/src/Renderer/TextRenderer.php
+++ b/src/Renderer/TextRenderer.php
@@ -201,7 +201,13 @@ public function renderHeader(Value $o): string
$s = '&'.$s;
}
- $output[] = $this->colorType($this->escape($s));
+ $s = $this->colorType($this->escape($s));
+
+ if ($o instanceof InstanceValue && isset($o->spl_object_id)) {
+ $s .= '#'.((int) $o->spl_object_id);
+ }
+
+ $output[] = $s;
}
if (null !== ($s = $o->getSize())) {
diff --git a/src/Zval/InstanceValue.php b/src/Zval/InstanceValue.php
index a65b33b54..323733474 100644
--- a/src/Zval/InstanceValue.php
+++ b/src/Zval/InstanceValue.php
@@ -32,6 +32,7 @@ class InstanceValue extends Value
public $type = 'object';
public $classname;
public $spl_object_hash;
+ public $spl_object_id = null;
public $filename;
public $startline;
public $hints = ['object'];
@@ -48,6 +49,7 @@ public function transplant(Value $old): void
if ($old instanceof self) {
$this->classname = $old->classname;
$this->spl_object_hash = $old->spl_object_hash;
+ $this->spl_object_id = $old->spl_object_id;
$this->filename = $old->filename;
$this->startline = $old->startline;
}
diff --git a/tests/Parser/ParserTest.php b/tests/Parser/ParserTest.php
index f2c06d883..4970ff4dc 100644
--- a/tests/Parser/ParserTest.php
+++ b/tests/Parser/ParserTest.php
@@ -354,6 +354,11 @@ public function testParseObject()
$this->assertSame(ChildTestClass::class, $o->classname);
$this->assertSame(\spl_object_hash($v), $o->spl_object_hash);
$this->assertContains('object', $o->hints);
+ if (KINT_PHP72) {
+ $this->assertSame(\spl_object_id($v), $o->spl_object_id);
+ } else {
+ $this->assertNull($o->spl_object_id);
+ }
$val = \array_values($o->value->contents);
@@ -475,6 +480,11 @@ public function testParseObjectIncomplete()
$this->assertSame(\spl_object_hash($v), $o->spl_object_hash);
$this->assertContains('object', $o->hints);
$this->assertNotNull($o->access_path);
+ if (KINT_PHP72) {
+ $this->assertSame(\spl_object_id($v), $o->spl_object_id);
+ } else {
+ $this->assertNull($o->spl_object_id);
+ }
$val = \array_values($o->value->contents);