|
Posted by comp.lang.php on 09/22/06 14:29
Tim Roberts wrote:
> "comp.lang.php" <phillip.s.powell@gmail.com> wrote:
> >
> >[PHP]
> > $array = array($firstOrderByFieldIfClause, $groupByClause,
> >$orderByClause);
> > array_walk($array, create_function('&$a', '$a = substr($a, 0,
> >strrpos(trim($a), ",")); if ($a) $a = ", $a";'));
> > print_r("firstOrderByFieldIfClause = $firstOrderByFieldIfClause and
> >groupByClause = $groupByClause and orderByClause = $orderByClause<P>");
> >[/PHP]
> >
> >Upon execution the fields within $array are never changed (verified by
> >checking code), and I don't understand why.
>
> It certainly does. Try "var_dump($array);", and you'll see that all three
> strings were changed.
>
> Your mistake is in thinking that changes to $array(0) will also affect
> $firstOrderByFieldIfClause.
>
> The array constructor makes three new strings.
I should have figured that all complex objects that take parameters
make clones of the parameters unless passed by reference. So that's
what I did:
$array = array(&$firstOrderByFieldIfClause, &$groupByClause,
&$orderByClause);
That did the trick, thanx!
Phil
> --
> - Tim Roberts, timr@probo.com
> Providenza & Boekelheide, Inc.
Navigation:
[Reply to this message]
|