I am SO confused (help with references!) (could be a bug?)

From: Date: Mon, 09 Apr 2001 12:40:22 +0000
Subject: I am SO confused (help with references!) (could be a bug?)
Groups: php.general 
Request: Send a blank email to php-general+get-47769@lists.php.net to get a copy of this message
If I were any more confused my head would split open. This just plain makes no sense, and I'm wondering if it's just a bug in PHP. Consider the following code: $arvar = array(&$var1, &$var2, &$var3); function vartest(&$arvar) { echo '<br>', $arvar[0], $arvar[1], $arvar[2]; $arvar[1] = 'Inside2 '; echo '<br>', $arvar[1]; } vartest($arvar); echo '<br>', $arvar[1]; echo '<br>', $var2; It outputs one blank line, then: ArrayArrayArray n n Inside2 Ok, so this is kind of weird. First, how the hell did those "n"s get in there? But that's not the weird part. If inside the function you use var_dump() on $arvar[0], var_dump returns NULL. If you run it on $arvar, you get NULL. So why did $arvar[0] get echo'ed as "Array", but it is in fact NULL? But if it's just one great big round of null, how did it change the value of $var2? Honestly, this is killing me here. Here is what I want to do: Pass $val1 and $val2 by reference into an array. Operate on the array inside of a function. Have the changes made to the array effect $val1 and $val2. In C I could use an array of pointers. But how in hell do I do it in PHP? Honestly, I'm at my wit's end here and I don't have a clue what is going on...I'll post again with some more insanely unbelievable confusing code results if need be. -- Plutarck Should be working on something... ...but forgot what it was.

« previous php.general (#47769) next »