|
-
Reef Shark
Array Disarray
Why doesn't this work?
Code:
function parse_error($handler,$error_message,$error_code = 0)
{
$handler["code"][] = $error_code;
$handler["message"][] = $error_message;
return $handler;
}
Nothing gets passed to the array... it's empty?? I originall tried this:
Code:
function parse_error($handler,$error_message,$error_code = 0)
{
array_push($handler["code"],$error_code);
array_push($handler["message"],$error_message);
return $handler;
}
~ And that is my humble opinion.
When I was a boy I was told that anybody could become President. Now I'm beginning to believe it. - Clarence Darrow
The greatness of a woman’s power is measured in the size and amount of the balls she clutches in hand. -Nephalim
"Tink"
1700+ XP on A7N8X, 768MB PC2700 DDRRAM, Samsung 19" 900IFT, Radeon 64MB DDR VIVO, SB Live! MP3+, 42.9GB IBM HDD, Plexwriter 8/4/32, 3C905CTXM NIC
"Hermes"
Dell Inspiron 8200, 1.7 GHz P4, 512MB DDRRAM, 30GB HDD, DVDROM, Geforce4 Go 64MB
-
Ursus Arctos Moderatis
I'm guessing that's PHP? The functions look pretty normal to me. I think your problem most likely lies in how you're using them. How are you calling parse_error()? How is the $handler array be initialized before hand? Why are you passing $handler by value instead of by reference?
-
Reef Shark
Yes, that's PHP... oops .
parse_error() adds an error to the handler much like array_push is supposed to add a node to a stack. Here is where $handler comes from:
Code:
function create_error_handler()
{
return array("code" => array(),"message" => array());
}
There really isn't a reason why I passed it by value than by reference except that I just didn't. I tend to think of references as ugly code too. Do you think that would work? I'll try it...
-
Ursus Arctos Moderatis
Yeah you might want to give it a try - to me that looks like a useful time to pass it by reference. In any case, I'd just work my way through a request inch by inch, placing a "die()" in key places to see what the $handler var contains at certain places in time. I'm sure you'll figure out where it gets emptied. Good luck.
-
Reef Shark
Wonder of all wonders, that little ampersand did the trick! Does that apply to all assosiative arrays I wonder? Is it that way purposefully in PHP? Anyway, I knew it had to be something stupifyingly simple. Thanks
-
Ursus Arctos Moderatis
If passing by reference was all you needed to do to fix the problem, than you were probably just not using your functions properly to begin with. I'm fairly certain you can pass arrays by value in PHP all the same, but passing by reference is preferable, at least in my opinion.
Generally speaking, when you need to call on complex and/or large data structures in functions, it's better to pass them by reference than by value. I'm not sure if I follow what you mean by passing-by-reference making ugly code, but either way, six of one half a dozen of the other, take your pick
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|