...

View Full Version : Undefined Variables



SDP2006
11-29-2003, 03:03 PM
I took this code, below, from http://www.oxyscripts.com/viewcode.php?id=22. This is just a few lines
<?php
function sdie($desc)
{
echo $desc;
exit;
}

Variables $desc. Where is it defined? This may be a beginner question, but as I have been moving into more advanced scripting as my knowledge empowers me, I see more of 'undefined' variables. Could someone tell me if I am wrong, or explain them to me?

Thanks

mordred
11-29-2003, 03:15 PM
$desc is a parameter to the function. It gets defined the moment you call the sdie() function, like sdie('hello world'). That's why your sample code hasn't got any undefined variables, everything is normal and ok here.

missing-score
11-29-2003, 03:15 PM
function sdie($desc)
{
echo $desc;
exit;
}

$desc is defined where shown above

missing-score
11-29-2003, 03:16 PM
mordred got there first with a much better explanation :)

SDP2006
11-29-2003, 03:37 PM
Mordred,

so when the code goes
echo $desc; what does it echo?

Thanks for the help

missing-score
11-29-2003, 04:15 PM
<?php

function sdie($desc)
{
echo $desc;
exit;
}

sdie('Hello World!'); // prints Hello World!

sdie('!dlroW olleH'); // prints !dlroW olleH

Nightfire
11-29-2003, 04:17 PM
<?php
function sdie($desc)
{
echo $desc;
exit;
}

sdie('Oooger Booger');

?>


Heh, beaten by a few mins :p

SDP2006
11-29-2003, 05:02 PM
Sweet, I see know! Thanks guys!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum