The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. February 11, 2012, 10:49:52 PM

Login with username, password and session length


Pages: 1 [2]
  Print  
Author Topic: Function - return 2 values?  (Read 2157 times)
walrus
Rookie
**
Offline Offline

Posts: 46


View Profile
« Reply #15 on: December 31, 2009, 11:34:15 PM »

This should also work.

Code:
function load_xml_feed($location, &$title, &$link, &$description)
{

    $feedXml = simplexml_load_file($location);

    $i= ‘1′;
    foreach ($feedXml->channel->item as $article)
    {
        $title[$i] = (string)$article->title;
        $link[$i] = (string)$article->link;
        $description[$i] = (string)$article->description;
        $i++;
    }

    $randnumber = rand(2, $i);
    $link = trim($link[$randnumber]);
    $title = trim($title[$randnumber]);
    $description = trim($description[$randnumber]);
    $title = iconv(“UTF-8″, “ISO-8859-1″, $title);
    $description = iconv(“UTF-8″, “ISO-8859-1″, $description);
}

load_xml_feed($rss, $title, $link, $description);
« Last Edit: December 31, 2009, 11:37:43 PM by walrus » Logged
herbacious
Journeyman
***
Offline Offline

Posts: 51


View Profile
« Reply #16 on: January 05, 2010, 06:33:22 AM »

this is where OO coding starts to make a lot more sense
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Online Online

Posts: 9792



View Profile
« Reply #17 on: January 05, 2010, 07:48:42 AM »

Passing variables by reference is a well known and oft-used way of getting more than one return value from a function.

I must have missed this: was this thread originally about NEEDING more than one value returned from a function or a security hole? It looked to me like a surprised coder, rather than a question...
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nop_90
Global Moderator
Lifer
*****
Offline Offline

Posts: 2203


View Profile
« Reply #18 on: January 05, 2010, 08:57:51 AM »

@perks
he thought you could return 2 value from a function by going

return a; return b;

but his code was messed up, he had declared a & b globals, so it was a bug.

I then pointed out that for PHP, globals if not used correctly used to be a security problem (version < 4)
Or if it has make post and gets into a global turned on.

Either way very bad programming practice globals.
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Online Online

Posts: 9792



View Profile
« Reply #19 on: January 05, 2010, 09:07:38 AM »

Very bad indeed. As we've echoed, globals == bad. For the vast majority of situations.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Online Online

Posts: 5604


Back in my day we had 9 planets


View Profile
« Reply #20 on: January 05, 2010, 09:25:10 AM »

to sum up.

coder was surprised and apparently confused.
nutballs made it worse.
nutballs finally actually looked at the code again and saw the globals.
nutballs = idiot
move along.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Online Online

Posts: 9792



View Profile
« Reply #21 on: January 05, 2010, 09:30:14 AM »

 ROFLMAO
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Pages: 1 [2]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!