Re: [PHP] quick php for perl coder question



Thomas Bolioli schreef:
I want to return an array from a function.
I have this:
return array($found, $username, $email, $nickname);
as my code. I have a bug in the code and I am not sure where yet. Should the above statement with this:

array($vars);

not sure what you meant with the line above, it's valid but does nothing.

$vars = function($type, $abc, $xyz);
$found = $vars[0];
$username = $vars[1];
$email = $vars[2];
$nickname = $vars[3];

on the other end work? If so, then the bug is somewhere else.

yes this should work assuming you meant this:

<?php

function foo() {
$found = true;
$username = 'The Joker';
$email = 'joker@xxxxxxxxxxx';
$nickname = 'joker';

return array($found, $username, $email, $nickname);
}

$vars = foo();
$found = $vars[0];
$username = $vars[1];
$email = $vars[2];
$nickname = $vars[3];
?>

although you could do it more perly:

<?php

list($found, $username, $email, $nickname) = foo();

?>

and maybe consider using an assoc array:

<?php

function foo() {
$found = true;
$username = 'The Joker';
$email = 'joker@xxxxxxxxxxx';
$nickname = 'joker';

return array(
'found' => $found,
'username' => $username,
'email' => $email,
'nickname' => $nickname,
);
}

$vars = foo();
// using an associative array negates the need to
// define the following variables, you can use
// $vars['found'] (etc) as it is quite descriptive
// in it's own right :-)
$found = $vars['found'];
$username = $vars['username'];
$email = $vars['email'];
$nickname = $vars['nickname'];

?>

Thanks in advance,
Tom


.



Relevant Pages

  • postnuke v 0.7.0.3 remote command execution
    ... post nuke is one of popular content management ... system written in php. ... there are bug in file user.php ... which user can append $caselist array with their own ...
    (Bugtraq)
  • Re: [PHP] unset in foreach breaks recrusion
    ... David Sky wrote: ... A couple of days ago I submitted a bug to PHP ... apparently it's not a bug. ...
    (php.general)
  • Re: php extensions compile error - another compile bug?
    ... Re: php extensions compile error - another compile bug?: ... Is not triviality is a matter of perspective? ... AFFECTS: users of PHP ... and shared extensions to allow more flexibility and add new features. ...
    (freebsd-questions)
  • Re: question about database injection
    ... i am working on the registeration page for the forum website and its ... USER NAME VALIDATION ... however i would like the username to be Letters First(upper or ... NOTE = in my php settings magic_quotes_gpc is ON, ...
    (comp.lang.php)
  • Re: login at a site.
    ... then the script redirects to ... $warning is a string to be ... Then test if the username and password entered match with the ones on ...
    (alt.php)