From fc644721451e02285e51ed2343c43f2f18b5f8a3 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 4 Aug 2024 16:28:18 +0200 Subject: [PATCH] Fix dumping callables on Node::__toString() --- src/Node/Node.php | 2 +- tests/Node/NodeTest.php | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/Node/NodeTest.php diff --git a/src/Node/Node.php b/src/Node/Node.php index 2da6bd88d..17b60dc35 100644 --- a/src/Node/Node.php +++ b/src/Node/Node.php @@ -54,7 +54,7 @@ class Node implements \Countable, \IteratorAggregate { $attributes = []; foreach ($this->attributes as $name => $value) { - $attributes[] = \sprintf('%s: %s', $name, str_replace("\n", '', var_export($value, true))); + $attributes[] = \sprintf('%s: %s', $name, is_callable($value) ? '\Closure' : str_replace("\n", '', var_export($value, true))); } $repr = [static::class.'('.implode(', ', $attributes)]; diff --git a/tests/Node/NodeTest.php b/tests/Node/NodeTest.php new file mode 100644 index 000000000..8e82af5b9 --- /dev/null +++ b/tests/Node/NodeTest.php @@ -0,0 +1,26 @@ + function () { return '1'; }], 1); + + $this->assertEquals('Twig\Node\Node(value: \Closure)', (string) $node); + } +}