[wp-hackers] Perhaps OT PHP Question

Matt Patenaude MattPat at mattpat.net
Tue May 29 01:42:01 GMT 2007


You're right about what he's doing, but shouldn't that also happen in  
PHP 5? Unless he precedes $category in the loop declaration with an  
ampersand, shouldn't it also operate as a copy in PHP 5? Or am I  
missing something?

-Matt

On May 28, 2007, at 9:34 PM, Sam Angove wrote:

> On 5/29/07, Chris Williams <chris at clwill.com> wrote:
>>
>> On my local test machine (php 5.2, wp 2.2) it works perfectly.  On  
>> the
>> server (php 4.?, wp 2.2) it doesn't.  The $categories array is  
>> unchanged.
>
> PHP 5 made changes to variable references. The loop isn't working
> because you're changing the cat_name on a copy of the category, then
> leaving that copy to be thrown away when the loop ends.
>
> For my money the simplest workaround is this:
>
> foreach ($categories as $key => $category) {
>   $categories[$key] = "whatever";
> }
>
> But there are half a dozen other options. Try the `foreach` page in
> the manual if you want more.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list