Re: Re: Re: Re: Re: Add form elements via hook_form_alter() to u

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15422
Re: Re: Re: Re: Re: Add form elements via hook_form_alter() to u

Alrighty... so... I've applied your patch and believe it'll work fine.

The other issue here is that TAPIr is using module_invoke_all() to call the table_alter functions. That won't accept/pass on arguments by reference, so I'm going to write a tapir_invoke_all() function that does. I'll post it up here when it's done... I'm also going to give this module some loving and post an update to d.o.

To get a better handle on references, just check out this code:

<?php
function func1(&$arg) {
  unset(
$arg[1]);
 
func2($arg);
}

function

func2(&$arg) {
  unset(
$arg[0]);
}

function

func3($arg) {
  unset(
$arg[2]);
}

$a = array(
 
0 => 'zero',
 
1 => 'one',
 
2 => 'two',
);

func1($a);
func3($a);

print_r($a);
?>

The result when run will be this:

Array
(
    [2] => two
)

Basically, & receives a reference to the variable, so the function will use the variable itself instead of make its own local copy. Notice that func3() doesn't use the &, so the unset() affects only the copy of $a inside that function. It's somewhat akin to pointers in other languages.