Printing the value of an object

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

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

I expect to get something like:

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.

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?

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?

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

@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).

And wouldn’t echo suffice here ?
Why do you want to output to var_dump ?

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

<?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:

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

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