6.0.0-beta1
7/11/25

[#3957] call_user_func always passes copy of Turba object to _turba_hook_encode_{attribute}
Summary call_user_func always passes copy of Turba object to _turba_hook_encode_{attribute}
Queue Turba
Queue Version 2.1.1
Type Bug
State Resolved
Priority 2. Medium
Owners Horde Developers (at)
Requester avo (at) trustsec (dot) de
Created 05/19/2006 (6993 days ago)
Due
Updated 05/22/2006 (6990 days ago)
Assigned 05/21/2006 (6991 days ago)
Resolved 05/22/2006 (6990 days ago)
Github Issue Link
Github Pull Request
Milestone
Patch No

History
05/22/2006 11:34:06 PM Chuck Hagenbuch Comment #9
State ⇒ Resolved
Reply to this comment
Okay, I was obviously on something; of course you'd get a 
call-time-blah-blah error with our current syntax. But using &$this 
with call_user_func_array() works fine.
05/22/2006 09:19:30 PM Jan Schneider Comment #8 Reply to this comment
Fine for me then.
05/22/2006 09:16:40 PM Chuck Hagenbuch Comment #7 Reply to this comment
No, that's how you need to wrap objects if you want a reference in an 
array. The array is what's being passed to the function.
05/22/2006 09:06:38 PM Jan Schneider Comment #6 Reply to this comment
Doesn't this produce call-time pass-by-reference notices?
05/22/2006 05:54:08 PM Chuck Hagenbuch Comment #5 Reply to this comment
That works, but you'll always get a reference.
Sure, but I'm not sure why that's a problem. Any other opinions here? Jan?
05/22/2006 07:07:38 AM avo (at) trustsec (dot) de Comment #4 Reply to this comment
True, but it'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 &$this instead of $this 
with the call_user_func
syntax?
That works, but you'll always get a reference. Here's an example:



function foo($x)

{

     $x = 42;

}

function bar(&$x)

{

     $x = 43;

}

$y = 0;

call_user_func('foo', &$y);

print "$y\n"; # -> 42

call_user_func('bar', &$y);

print "$y\n"; # -> 43



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



function foo($x)

{

     $x = 42;

}

function bar(&$x)

{

     $x = 43;

}

$y = 0;

foo($y);

print "$y\n"; # -> 0

bar($y);

print "$y\n"; # -> 43



I don't know what's more sensible in this case.
05/21/2006 04:36:25 AM Chuck Hagenbuch Comment #3
State ⇒ Feedback
Reply to this comment
True, but it'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 
&$this instead of $this with the call_user_func syntax?
05/21/2006 04:34:03 AM Chuck Hagenbuch Deleted Original Message
 
05/19/2006 05:36:25 PM avo (at) trustsec (dot) de Comment #2 Reply to this comment
On my way back home after work it crossed my mind that I could 
subclass Turba's LDAP driver instead of "abusing" the encode hooks to 
set additional LDAP attributes. I think that subclassing the LDAP 
driver is a much better solution since it doesn't require any changes 
to Horde. I'm sorry for bothering you!
05/19/2006 10:26:26 AM Jan Schneider Assigned to Horde DevelopersHorde Developers
 
05/19/2006 10:26:01 AM Jan Schneider State ⇒ Assigned
 
05/19/2006 09:44:28 AM avo (at) trustsec (dot) de Comment #1
Priority ⇒ 2. Medium
Type ⇒ Bug
Summary ⇒ call_user_func always passes copy of Turba object to _turba_hook_encode_{attribute}
Queue ⇒ Turba
New Attachment: patch-turba_lib_Object_php.diff
State ⇒ Unconfirmed
Reply to this comment
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's not 
possible to get a reference to the object and thus it isn't possible 
to modify the object in the hook function.



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



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



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

{

     $firstname = $new_value;

     $lastname = $turba_object->getValue('firstname');

     $name = $firstname . ' ' . $lastname;

     $turba_object->setValue('displayname', $name);

     $turba_object->setValue('cn', $name);

     return $new_value;

}



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



It's highly unlikely that this change will break existing hook 
functions. I don't think that anyone has requested a reference to the 
Turba object but then expects to get a copy of the object.

Saved Queries