<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet href="https://dev.horde.org/themes/horde//default/feed-rss.xsl" type="text/xsl"?> 
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> 
 <channel> 
  <title>call_user_func always passes copy of Turba object to _turba_hook_encode_{attribute}</title> 
  <pubDate>Thu, 09 Apr 2026 18:03:12 +0000</pubDate> 
  <link>https://bugs.horde.org/ticket/3957</link> 
  <atom:link rel="self" type="application/rss+xml" title="call_user_func always passes copy of Turba object to _turba_hook_encode_{attribute}" href="https://bugs.horde.org/ticket/3957/rss" /> 
  <description>call_user_func always passes copy of Turba object to _turba_hook_encode_{attribute}</description> 
 
   
   
  <item> 
   <title>The hook functions _turba_hook_encode_{attribute} and _turba</title> 
   <description>The hook functions _turba_hook_encode_{attribute} and _turba_hook_decode_{attribute} always get a copy of the Turba object since the hook functions are called with call_user_func. It&#039;s not possible to get a reference to the object and thus it isn&#039;t possible to modify the object in the hook function.



For example, I&#039;d like to concatenate the first name and last name and store that value in the attributes &quot;displayname&quot; and &quot;cn&quot;. I&#039;d also like to construct the &quot;postalAddress&quot; from &quot;street&quot;, &quot;postalCode&quot;, &quot;location&quot; etc.



This is only possible if I can get a reference to the Turba object instead of a copy. Here&#039;s an example hook function:



function _turba_hook_encode_firstname($new_value, $old_value, &amp;$turba_object)

{

    $firstname = $new_value;

    $lastname = $turba_object-&gt;getValue(&#039;firstname&#039;);

    $name = $firstname . &#039; &#039; . $lastname;

    $turba_object-&gt;setValue(&#039;displayname&#039;, $name);

    $turba_object-&gt;setValue(&#039;cn&#039;, $name);

    return $new_value;

}



I&#039;ve attached a small patch that replaces call_user_func in turba/lib/Object.php with direct function calls.



It&#039;s highly unlikely that this change will break existing hook functions. I don&#039;t think that anyone has requested a reference to the Turba object but then expects to get a copy of the object.</description> 
   <pubDate>Fri, 19 May 2006 09:44:28 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/3957#t20397</link> 
  </item> 
   
  <item> 
   <title>On my way back home after work it crossed my mind that I cou</title> 
   <description>On my way back home after work it crossed my mind that I could subclass Turba&#039;s LDAP driver instead of &quot;abusing&quot; the encode hooks to set additional LDAP attributes. I think that subclassing the LDAP driver is a much better solution since it doesn&#039;t require any changes to Horde. I&#039;m sorry for bothering you!</description> 
   <pubDate>Fri, 19 May 2006 17:36:25 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/3957#t20410</link> 
  </item> 
   
  <item> 
   <title>True, but it&#039;s also useful to be able to modify the object, </title> 
   <description>True, but it&#039;s also useful to be able to modify the object, and part of the reason the $this parameter was added. Can you test with using &amp;$this instead of $this with the call_user_func syntax?</description> 
   <pubDate>Sun, 21 May 2006 04:36:25 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/3957#t20443</link> 
  </item> 
   
  <item> 
   <title>&gt; True, but it&#039;s also useful to be able to modify the object</title> 
   <description>&gt; True, but it&#039;s also useful to be able to modify the object, and part of the reason the $this

&gt; parameter was added. Can you test with using &amp;$this instead of $this with the call_user_func 

&gt; syntax?



That works, but you&#039;ll always get a reference. Here&#039;s an example:



function foo($x)

{

    $x = 42;

}

function bar(&amp;$x)

{

    $x = 43;

}

$y = 0;

call_user_func(&#039;foo&#039;, &amp;$y);

print &quot;$y\n&quot;; # -&gt; 42

call_user_func(&#039;bar&#039;, &amp;$y);

print &quot;$y\n&quot;; # -&gt; 43



If the function is called directly you can decide in the hook function whether you&#039;d like to get a reference or a copy:



function foo($x)

{

    $x = 42;

}

function bar(&amp;$x)

{

    $x = 43;

}

$y = 0;

foo($y);

print &quot;$y\n&quot;; # -&gt; 0

bar($y);

print &quot;$y\n&quot;; # -&gt; 43



I don&#039;t know what&#039;s more sensible in this case.</description> 
   <pubDate>Mon, 22 May 2006 07:07:38 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/3957#t20467</link> 
  </item> 
   
  <item> 
   <title>&gt; That works, but you&#039;ll always get a reference.



Sure, bu</title> 
   <description>&gt; That works, but you&#039;ll always get a reference.



Sure, but I&#039;m not sure why that&#039;s a problem. Any other opinions here? Jan?</description> 
   <pubDate>Mon, 22 May 2006 17:54:08 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/3957#t20494</link> 
  </item> 
   
  <item> 
   <title>Doesn&#039;t this produce call-time pass-by-reference notices?</title> 
   <description>Doesn&#039;t this produce call-time pass-by-reference notices?</description> 
   <pubDate>Mon, 22 May 2006 21:06:38 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/3957#t20500</link> 
  </item> 
   
  <item> 
   <title>No, that&#039;s how you need to wrap objects if you want a refere</title> 
   <description>No, that&#039;s how you need to wrap objects if you want a reference in an array. The array is what&#039;s being passed to the function.</description> 
   <pubDate>Mon, 22 May 2006 21:16:40 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/3957#t20502</link> 
  </item> 
   
  <item> 
   <title>Fine for me then.</title> 
   <description>Fine for me then.</description> 
   <pubDate>Mon, 22 May 2006 21:19:30 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/3957#t20503</link> 
  </item> 
   
  <item> 
   <title>Okay, I was obviously on something; of course you&#039;d get a ca</title> 
   <description>Okay, I was obviously on something; of course you&#039;d get a call-time-blah-blah error with our current syntax. But using &amp;$this with call_user_func_array() works fine.</description> 
   <pubDate>Mon, 22 May 2006 23:34:06 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/3957#t20507</link> 
  </item> 
   
   
 
 </channel> 
</rss> 
