[PHP] Re: problem with passing-by-reference

2010-05-14 Thread Rene Veerman
> On Fri, May 14, 2010 at 10:09 AM, Rene Veerman  wrote:
>> Hi.
>>
>> I'm doing the 5.3-strict thing, and am removing all my
>> passing-by-reference muck from a script of mine.
>>
>> But i've run into a problem;
>>
>> I use the following construct to push new values fairly deeply inside
>> an array structure;
>>
>> $chase = chaseToReference ($wm, $path);
>> $arr = result($chase);
>> $arr[$v] = $lid;
>>
>> $path is a flat-list array of indexes in $wm that have to be traversed
>> to get to the right portion of $wm.
>> a debug-dump of $wm and $arr after running this code shows $arr
>> correctly updated, but $wm not. :((
>>
>> here are the functions involved, any help is much appreciated.
>>
>> function chaseToReference (&$array, $path) {
>>  if (!empty($path)) {
>>    if (empty($array[$path[0]])) {
>>                        return badResult (E_USER_WARNING, array(
>>                                'msg' => 'Could not walk the full tree',
>>                                '$path' => $path,
>>                                '$array (possibly partially walked)' => $array
>>                        ));
>>    } else return chaseToReference($array[$path[0]], array_slice($path, 1));
>>  } else {
>>    return goodResult($array);
>>  }
>> }
>>
>> function result(&$r) {
>>  return $r['result'];
>> }
>>
>> function goodResult(&$r) {
>>  $r2 = array (
>>  'isMetaForFunc' => true,
>>        'result' => &$r
>>  );
>>  return $r2;
>> }
>>

On Fri, May 14, 2010 at 10:39 AM, Rene Veerman  wrote:
> changed all function-definitions to include a "&" before their name,
> no change in behavior though..
>

And then, change the calling code to:

$chase = &chaseToReference ($wm, $path);
$arr = &result($chase);
$arr[$v] = $lid;


and it works :))

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: problem with passing-by-reference

2010-05-14 Thread Rene Veerman
changed all function-definitions to include a "&" before their name,
no change in behavior though..

On Fri, May 14, 2010 at 10:09 AM, Rene Veerman  wrote:
> Hi.
>
> I'm doing the 5.3-strict thing, and am removing all my
> passing-by-reference muck from a script of mine.
>
> But i've run into a problem;
>
> I use the following construct to push new values fairly deeply inside
> an array structure;
>
> $chase = chaseToReference ($wm, $path);
> $arr = result($chase);
> $arr[$v] = $lid;
>
> $path is a flat-list array of indexes in $wm that have to be traversed
> to get to the right portion of $wm.
> a debug-dump of $wm and $arr after running this code shows $arr
> correctly updated, but $wm not. :((
>
> here are the functions involved, any help is much appreciated.
>
> function chaseToReference (&$array, $path) {
>  if (!empty($path)) {
>    if (empty($array[$path[0]])) {
>                        return badResult (E_USER_WARNING, array(
>                                'msg' => 'Could not walk the full tree',
>                                '$path' => $path,
>                                '$array (possibly partially walked)' => $array
>                        ));
>    } else return chaseToReference($array[$path[0]], array_slice($path, 1));
>  } else {
>    return goodResult($array);
>  }
> }
>
> function result(&$r) {
>  return $r['result'];
> }
>
> function goodResult(&$r) {
>  $r2 = array (
>  'isMetaForFunc' => true,
>        'result' => &$r
>  );
>  return $r2;
> }
>
>
>
> --
> -
> Greetings from Rene7705,
>
> My free open source webcomponents:
>  http://code.google.com/u/rene7705/
>  http://mediabeez.ws/downloads (and demos)
>
> http://www.facebook.com/rene7705
> -
>



-- 
-
Greetings from Rene7705,

My free open source webcomponents:
  http://code.google.com/u/rene7705/
  http://mediabeez.ws/downloads (and demos)

http://www.facebook.com/rene7705
-

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php