Re: inner workings of extract

From: Date: Sat, 24 Mar 2001 00:40:00 +0000
Subject: Re: inner workings of extract
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-45381@lists.php.net to get a copy of this message
It shouldn't matter, but try moving the global *AFTER* the extract(). Meanwhile, I think you should probably report this at http://bugs.php.net Seems pretty broken to this naive user... (Who likes the idea of extract, but can never remember the darn function name when I need it...) -- Visit the Zend Store at http://www.zend.com/store/ Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm ----- Original Message ----- From: <dempsejn@georgetown.edu> Newsgroups: php.general Sent: Friday, March 16, 2001 2:13 PM Subject: [PHP] inner workings of extract > Hi all, > > I've recently discovered the extract function (thanks to the poster > regarding it), and have found it to save lots of time. > I'm having a problem though. 99 times out of 100 when someone thinks > they've found a "bug" it's actually their misuse of the function, so > i'm > pretty sure this is the case with me. Anyway, here's the deal: > > I have a function. Inside this function i have > > global $name, $type, $location; (and others) > > I make a call to a mysql database and get the result in $result. > Then I used to do this: > > $name = $row["name"]; > $type = $type["type"]; > etc. > > extract makes this a lot nicer. However, at the end of this function i > call another function. This also uses the same global variables. Previous > this worked fine. But now that i'm using extract, while i do have access > to the variables in the function, i can't get them in the next. > > My guess is that the way extract works, (somehow, who knows), its > creating a local variable named $name and setting my info to that, as > opposed to $name = $row["name"] which sets the global. So, even though i > can access $name in the function, its lost to the next. > This isn't a huge issue--i can go back to the old way, or pass the > variables in the function, but there are enough that i wanted to know if > anyone else has experienced this. Is there some way to tell extract to > extract the variables and set the results to the global versions? > Maybe i'm way off and its a small code error, but I really do doubt this, > as i've commented out lines and gone back and forth and get the same > result. here's the basic idea though: > function tester(){ > global $name; > $row = mysql_fetch_array($sql_result); > $name = $row["name"]; > nextone(); > /*this works fine, but if i have extract($row) and comment out > the $name = $row["name"] line, then i can't see the variable in the > next function*/ > > } > function nextone(){ > global $name; > echo $name; > } > > any ideas? > > thanks, > jack > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#45381) next »