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 |
State ⇒ Resolved
call-time-blah-blah error with our current syntax. But using &$this
with call_user_func_array() works fine.
array. The array is what's being passed to the function.
of the reason the $this
parameter was added. Can you test with using &$this instead of $this
with the call_user_func
syntax?
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.
State ⇒ Feedback
of the reason the $this parameter was added. Can you test with using
&$this instead of $this with the call_user_func syntax?
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!
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
_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.