# Printing the value of an object

**URL:** <https://forum.getkirby.com/t/printing-the-value-of-an-object/4775>\
**Category:** Questions\
**Tags:** v2\
**Created:** [July 24, 2016, 6:23pm UTC](https://forum.getkirby.com/t/printing-the-value-of-an-object/4775 "2016-07-24T18:23:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![andy](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/andy/32/852_2.png) [@andy](https://forum.getkirby.com/u/andy)\
**Post date:** [July 24, 2016, 6:23pm UTC](https://forum.getkirby.com/t/printing-the-value-of-an-object/4775/1 "2016-07-24T18:23:43Z")

</div>

I simply want to dump the value of a variable saved in Kirby using PHP’s `var_dump()` function. If I do the following:

```auto
<?php var_dump($page->title()->html()); ?>

```

I expect to get something like:

```auto
string(5) "About"

```

What I get instead is a gigantic object (around 900 lines and nearly 500kb) that contains all the data of the entire site. All I want is to see the actual variable I asked for (in this case, the value of the page title) and not everything else.

```auto
object(Field) #90 (3) { ["page"]= > object(Page) #71 (11) { ["kirby"]= > object(Kirby) #3 (15) { ["roots"]= > object(Kirby\ Roots) #4 (1) { ["index"]= > string(31)
"/Users/<username>/Dev/<sitename>"
}["urls"] => object(Kirby\ Urls) #5 (8) { ["index"]= > string(35)
"http://dev.<sitename>:8888" ["indexDetected"] => bool(true)["content"] => NULL["thumbs"] => NULL["assets"] => NULL["autocss"] => NULL["autojs"] => NULL["avatars"] => NULL
}["cache"] => object(Cache\ Driver\ Mock) #14 (1) { ["options":protected]= > array(0) {}
}["path"] => string(5)
"about" ["options"] => array(36) {
    ["tinyurl.enabled"] => bool(true)["tinyurl.folder"] => string(1)
    "x" ["url"] => bool(false)["timezone"] => string(15)
    "America/Chicago" ["license"] => string(32)
    "1940dc58ec98de46245b5f1545589044" ["rewrite"] => bool(true)["error"] => string(5)
    ... Plus 900 more lines

```

Why do I get this gigantic object when I’m asking for a subset of it, and how do I get around that?

---

<div class="post-metadata">

**Author:** ![Thiousi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thiousi/32/13656_2.png) [@Thiousi](https://forum.getkirby.com/u/Thiousi)\
**Post date:** [July 24, 2016, 6:33pm UTC](https://forum.getkirby.com/t/printing-the-value-of-an-object/4775/2 "2016-07-24T18:33:05Z")

</div>

Hey, try to use `<?php print_r($page->title()->html()); ?>` instead.

var\_dump tends to get all the links from the object contained within it. As explained by @distantnative here: [Leaking object?](https://forum.getkirby.com/t/leaking-object/2503/3?u=thiousi)

I’m not sure if it is to be expected when just outputting the title, though.

---

<div class="post-metadata">

**Author:** ![andy](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/andy/32/852_2.png) [@andy](https://forum.getkirby.com/u/andy)\
**Post date:** [July 24, 2016, 6:47pm UTC](https://forum.getkirby.com/t/printing-the-value-of-an-object/4775/3 "2016-07-24T18:47:35Z")

</div>

@Thiousi, `print_r()` shows nearly the same information—`var_dump()` only adds the type of variable at the beginning (`string(5) "About"`, as an example).

---

<div class="post-metadata">

**Author:** ![Thiousi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thiousi/32/13656_2.png) [@Thiousi](https://forum.getkirby.com/u/Thiousi)\
**Post date:** [July 24, 2016, 6:49pm UTC](https://forum.getkirby.com/t/printing-the-value-of-an-object/4775/4 "2016-07-24T18:49:00Z")

</div>

And wouldn’t echo suffice here ?  
Why do you want to output to var\_dump ?

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [July 24, 2016, 7:17pm UTC](https://forum.getkirby.com/t/printing-the-value-of-an-object/4775/5 "2016-07-24T19:17:08Z")

</div>

If you want to get the value of a field, use:

```php
<?php var_dump($page->title()->value()); ?>

```

This returns the actual value without the object references.

You can also combine the two, only make sure that `value()` is the last in the chain:

```auto
<?php var_dump($page->title()->html()->value()); ?>

```

---

<div class="post-metadata">

**Author:** ![andy](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/andy/32/852_2.png) [@andy](https://forum.getkirby.com/u/andy)\
**Post date:** [July 24, 2016, 7:31pm UTC](https://forum.getkirby.com/t/printing-the-value-of-an-object/4775/6 "2016-07-24T19:31:29Z")

</div>

@lukasbestle Ah, that’s what I was looking for, thank you!

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 4:57pm UTC](https://forum.getkirby.com/t/printing-the-value-of-an-object/4775/7 "2025-02-06T16:57:29Z")

</div>

Archived on February 6, 2025, 4:57pm UTC


