PHP Passing Through Confusion

In short, I have the following function as part of my framework:

public function use_parameters()
{
    $parameters = func_get_args();

    $stack = debug_backtrace();

    foreach($stack[0]['args'] as $key => &$parameter)
    {
        $parameter = array_shift($this->parameter_values);
    }
}

Where $ this-> parameter_values ​​= array ('value1', 'value2', 'value3', 'value4', 'value5', ...);

Used in the following context:

$instance->use_parameters(&$foo, &$bah);

Appointment:

$foo = 'value1';
$bah = 'value2';

Call again

$instance->use_parameters(&$something); 

Sets

$something = 'value3'

etc.

Beginning with 5.3, it will return the warning "Deprecated: approach time outdated." Trying to comply with 5.3 method of work, I deleted and received:

$instance->use_parameters($foo, $bah);

Unfortunately, these arguments have not been established, and I am struggling to find a solution.

Why run PHP v5.3.3-7 on Apache / 2.2.16 (Debian)

Any help would be greatly appreciated.

+5
source share
2 answers

PHP, . , . NULL , , . , , , , :

    const dummy="^^missing^^";

    public function use_parameters(&$a, &$b=self::dummy, &$c=self::dummy ) {
        $a=array_shift($this->parameter_values);
        if($b!==self::dummy) $b=array_shift($this->parameter_values);
        if($c!==self::dummy) $c=array_shift($this->parameter_values);
        # add $d,$e,$f,... as required to a sensible max number
    }

, , , debug_backtrace() botch.

+2

PHP 5 ... , . , :

public function use_parameters(&$arg1, &$arg2 = NULL, &$arg3 = NULL)
{
    // if ($arg2 !== NULL)
    // if ($arg3 !== NULL)
}

$parameters = array(0 => &$foo, 1 => &$bah);

public function use_parameters($args)
{
    // Handle the array elements
}
+1

All Articles