Jump to content

function with passing reference


dreerr
 Share

Recommended Posts

Dear Community,

Trying to do add some field values programmatically, it works fine like this:

// field 'author' does not exist in template
$page->author="{$page->author_first} {$page->author_last}";
echo $page->author;
// prints "John Doe"

due to my structure it would be nice to have this within a function with passing by reference, sadly it does not work like this:

function renderAuthorInfo(&$page)
{
	$page->author="{$page->author_first} {$page->author_last}";
}

renderAuthorInfo($page);
echo $page->author;
// Not working

What am I missing here? Or is it just not possible to do it like this with PHP objects?

The code is only an example, I'm not actually trying to put first and last name together, but something more complex.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...