dreerr Posted August 7, 2013 Share Posted August 7, 2013 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 More sharing options...
Soma Posted August 7, 2013 Share Posted August 7, 2013 ...nothing, this works ok. Don't know why it shouldn't. Link to comment Share on other sites More sharing options...
teppo Posted August 7, 2013 Share Posted August 7, 2013 Did couple of quick tests and there's no problem with this (just like @Soma pointed out above.) Sounds like it's something about your "more complex" thing that's broken. 1 Link to comment Share on other sites More sharing options...
nik Posted August 7, 2013 Share Posted August 7, 2013 ..and there's no need to pass an object explicitly by reference in the first place. Just pass by value and it works as expected (for that part, that is). See PHP: Objects and references for more information. And in case it was for performance benefits, read "Do not use PHP references" as well. 2 Link to comment Share on other sites More sharing options...
dreerr Posted August 7, 2013 Author Share Posted August 7, 2013 Thanks guys, bit to tired today, maybe forgot to save the file working fine here! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now