Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #10821 > unrolled thread
| Started by | Twayne <nobody@spamcop.net> |
|---|---|
| First post | 2013-09-21 16:20 -0400 |
| Last post | 2013-09-22 16:57 -0400 |
| Articles | 13 — 6 participants |
Back to article view | Back to comp.lang.php
Setting & displaying Variables Twayne <nobody@spamcop.net> - 2013-09-21 16:20 -0400
Re: Setting & displaying Variables Jerry Stuckle <jstucklex@attglobal.net> - 2013-09-21 16:25 -0400
Re: Setting & displaying Variables The Natural Philosopher <tnp@invalid.invalid> - 2013-09-21 21:29 +0100
Re: Setting & displaying Variables Richard Damon <Richard@Damon-Family.org> - 2013-09-21 16:47 -0400
Re: Setting & displaying Variables Twayne <nobody@spamcop.net> - 2013-09-22 16:47 -0400
Re: Setting & displaying Variables Richard Damon <Richard@Damon-Family.org> - 2013-09-22 17:58 -0400
Re: Setting & displaying Variables Richard Yates <richard@yatesguitar.com> - 2013-09-21 14:29 -0700
Re: Setting & displaying Variables Twayne <nobody@spamcop.net> - 2013-09-22 16:54 -0400
Re: Setting & displaying Variables Twayne <nobody@spamcop.net> - 2013-09-22 17:19 -0400
Re: Setting & displaying Variables Richard Yates <richard@yatesguitar.com> - 2013-09-22 14:39 -0700
Re: Setting & displaying Variables Twayne <nobody@spamcop.net> - 2013-09-23 19:54 -0400
Re: Setting & displaying Variables "J.O. Aho" <user@example.net> - 2013-09-21 23:55 +0200
Re: Setting & displaying Variables Twayne <nobody@spamcop.net> - 2013-09-22 16:57 -0400
| From | Twayne <nobody@spamcop.net> |
|---|---|
| Date | 2013-09-21 16:20 -0400 |
| Subject | Setting & displaying Variables |
| Message-ID | <l1kv32$ll0$1@speranza.aioe.org> |
Hi,
Obviously, the issue is around the comments var. It works, but it
doesn't and I'm hoping someone can explain why.
Both echo strlen($comments); and echo $comments; throw a Notice
about an undefined variable. But the variable "comments" HAS to have
been defined in order for the two echo statements to work!
The variable 'comments' is also in SESSION data, which will also get
the same Notice of an undefined variable.
What the heck am I missing? Why do I get the undefined var in those two
statements?
===================
<code>
echo strlen($_POST["comments"])."<br />"; //WORKS
$commments = $_POST["comments"]; // WORKS but not needed; done elsewhere
too.
// echo strlen($comments); // GETS Notice: Undefined variable: comments
in C:\xampp\htdocs... and nothing displays.
echo $_POST["comments"]; // WORKS
//echo $comments; // GETS Notice: Undefined variable: comments in C
... and nothing displays.
</code>
===================
I'm obviously missing something here since it appears the var is set
according to the 2 statements that do display what I expected. Can you
straighten me out? I've had this happen before with other vars and it's
always confusing.
TIA,
Twayne`
[toc] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2013-09-21 16:25 -0400 |
| Message-ID | <l1kvbt$c3h$1@dont-email.me> |
| In reply to | #10821 |
On 9/21/2013 4:20 PM, Twayne wrote: > Hi, > > Obviously, the issue is around the comments var. It works, but it > doesn't and I'm hoping someone can explain why. > > Both echo strlen($comments); and echo $comments; throw a Notice > about an undefined variable. But the variable "comments" HAS to have > been defined in order for the two echo statements to work! > The variable 'comments' is also in SESSION data, which will also get > the same Notice of an undefined variable. > > What the heck am I missing? Why do I get the undefined var in those two > statements? > > =================== > <code> > echo strlen($_POST["comments"])."<br />"; //WORKS > > $commments = $_POST["comments"]; // WORKS but not needed; done elsewhere > too. > > // echo strlen($comments); // GETS Notice: Undefined variable: comments > in C:\xampp\htdocs... and nothing displays. > > echo $_POST["comments"]; // WORKS > //echo $comments; // GETS Notice: Undefined variable: comments in C > ... and nothing displays. > > </code> > =================== > > I'm obviously missing something here since it appears the var is set > according to the 2 statements that do display what I expected. Can you > straighten me out? I've had this happen before with other vars and it's > always confusing. > > TIA, > > Twayne` > > Your code is obviously screwed up. But by posting excerpts of your code, you make it impossible for anyone to tell you what you screwed up. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Date | 2013-09-21 21:29 +0100 |
| Message-ID | <l1kvju$rmc$1@news.albasani.net> |
| In reply to | #10821 |
On 21/09/13 21:20, Twayne wrote: > I'm obviously missing something here > Twayne` > Probably a brain. > -- Ineptocracy (in-ep-toc’-ra-cy) – a system of government where the least capable to lead are elected by the least capable of producing, and where the members of society least likely to sustain themselves or succeed, are rewarded with goods and services paid for by the confiscated wealth of a diminishing number of producers.
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <Richard@Damon-Family.org> |
|---|---|
| Date | 2013-09-21 16:47 -0400 |
| Message-ID | <mBn%t.21487$lr1.2548@en-nntp-07.dc1.easynews.com> |
| In reply to | #10821 |
On 9/21/13 4:20 PM, Twayne wrote: > Hi, > > Obviously, the issue is around the comments var. It works, but it > doesn't and I'm hoping someone can explain why. > > Both echo strlen($comments); and echo $comments; throw a Notice > about an undefined variable. But the variable "comments" HAS to have > been defined in order for the two echo statements to work! > The variable 'comments' is also in SESSION data, which will also get > the same Notice of an undefined variable. > > What the heck am I missing? Why do I get the undefined var in those two > statements? > > =================== > <code> > echo strlen($_POST["comments"])."<br />"; //WORKS > > $commments = $_POST["comments"]; // WORKS but not needed; done elsewhere > too. > > // echo strlen($comments); // GETS Notice: Undefined variable: comments > in C:\xampp\htdocs... and nothing displays. > > echo $_POST["comments"]; // WORKS > //echo $comments; // GETS Notice: Undefined variable: comments in C > ... and nothing displays. > > </code> > =================== > > I'm obviously missing something here since it appears the var is set > according to the 2 statements that do display what I expected. Can you > straighten me out? I've had this happen before with other vars and it's > always confusing. > > TIA, > > Twayne` > > As others have commented on, not showing us the full code makes it very hard to help. The error message you are quoting says that the variable does NOT at that point have a value assigned to it. You say that the variables have to be defined for the echo statements to work, but then you also say that you get the error because they are not defined. Note that PHP is not like more strictly declared languages, you do not need to "create" variables explicitly to use them, they will be created as needed. Thus a script like: <?php echo $comment ?> will "work" in the sense that the PHP language defines what it will generate, which includes a possible "Notice" due to using the value of a variable that was never set, and thus is possibly wrong, but is defined (which is the reason it is just a NOTICE, one of the lower levels of messages defined). Another comment is your "WORKS but not needed, done elsewhere" statement, that might be refering to the now obsolete functionality of inserting into the global variable space the contents of some of the "super-globals" like $_POST. Older version of PHP would default to this behavior, later ones defaulted to not doing this behavior, and the latest version (if I remember right), no longer have the option to do this behavior (except via explicit script code). If you script depended on this behavior, and was moved or the server upgraded, then it could break for this reason.
[toc] | [prev] | [next] | [standalone]
| From | Twayne <nobody@spamcop.net> |
|---|---|
| Date | 2013-09-22 16:47 -0400 |
| Message-ID | <l1nl0i$f9l$1@speranza.aioe.org> |
| In reply to | #10824 |
On 2013-09-21 4:47 PM, Richard Damon wrote:
> On 9/21/13 4:20 PM, Twayne wrote:
>> Hi,
>>
>> Obviously, the issue is around the comments var. It works, but it
>> doesn't and I'm hoping someone can explain why.
>>
>> Both echo strlen($comments); and echo $comments; throw a Notice
>> about an undefined variable. But the variable "comments" HAS to have
>> been defined in order for the two echo statements to work!
>> The variable 'comments' is also in SESSION data, which will also get
>> the same Notice of an undefined variable.
>>
>> What the heck am I missing? Why do I get the undefined var in those two
>> statements?
>>
>> ===================
>> <code>
>> echo strlen($_POST["comments"])."<br />"; //WORKS
>>
>> $commments = $_POST["comments"]; // WORKS but not needed; done elsewhere
>> too.
>>
>> // echo strlen($comments); // GETS Notice: Undefined variable: comments
>> in C:\xampp\htdocs... and nothing displays.
>>
>> echo $_POST["comments"]; // WORKS
>> //echo $comments; // GETS Notice: Undefined variable: comments in C
>> ... and nothing displays.
>>
>> </code>
>> ===================
...
>
> As others have commented on, not showing us the full code makes it very
> hard to help. The error message you are quoting says that the variable
> does NOT at that point have a value assigned to it.
No, and I doubt anyone would go thru 500 lines of code even if I were
allowed to post it.
That said, the snippet above is ONE snippet of consecutive code lines;
they are not simply gathered into one place; That's the precise order
they occur in.
>
> You say that the variables have to be defined for the echo statements to
> work, but then you also say that you get the error because they are not
> defined.
No I say they're defined; as evidenced by the working code I indicated.
PHP/ my Local Server are tossing up the " Notice; undefined ... "
messages.
>
> Note that PHP is not like more strictly declared languages, you do not
> need to "create" variables explicitly to use them, they will be created
> as needed.
Of course I understand that!
Thus a script like:
>
> <?php
> echo $comment
> ?>
>
> will "work" in the sense that the PHP language defines what it will
> generate, which includes a possible "Notice" due to using the value of a
> variable that was never set, and thus is possibly wrong, but is defined
> (which is the reason it is just a NOTICE, one of the lower levels of
> messages defined).
Of course; nothing new there.
>
> Another comment is your "WORKS but not needed, done elsewhere"
> statement, that might be refering to the now obsolete functionality of
> inserting into the global variable space the contents of some of the
> "super-globals" like $_POST.
That doesn't make a lot of sense, whatever idea you wanted to get
across. There are no obsolete issues like that and $_POST functions
properly in myriad other places where it's used.
If I'm missing your point, please clarify further; you can't say
$_POST is obsolete, which appears to be your point here.
Older version of PHP would default to this
> behavior,
Using PHP 5.3.x and HTML 5; 5 has not obsoleted anything I've done.
later ones defaulted to not doing this behavior, and the
> latest version (if I remember right), no longer have the option to do
> this behavior (except via explicit script code). If you script depended
> on this behavior, and was moved or the server upgraded, then it could
> break for this reason.
There have been zero changes on the server; it's my own local server and
like I said, is not obsoleting anything I'm aware of.
I'm sorry, but none of that last para makes much sense in the context of
the query I posed.
Regards,
Twayne`
>
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <Richard@Damon-Family.org> |
|---|---|
| Date | 2013-09-22 17:58 -0400 |
| Message-ID | <ZJJ%t.21791$lr1.11844@en-nntp-07.dc1.easynews.com> |
| In reply to | #10830 |
On 9/22/13 4:47 PM, Twayne wrote: > On 2013-09-21 4:47 PM, Richard Damon wrote: >> On 9/21/13 4:20 PM, Twayne wrote: >>> Hi, >>> >>> Obviously, the issue is around the comments var. It works, but it >>> doesn't and I'm hoping someone can explain why. >>> >>> Both echo strlen($comments); and echo $comments; throw a Notice >>> about an undefined variable. But the variable "comments" HAS to have >>> been defined in order for the two echo statements to work! >>> The variable 'comments' is also in SESSION data, which will also get >>> the same Notice of an undefined variable. >>> >>> What the heck am I missing? Why do I get the undefined var in those two >>> statements? >>> >>> =================== >>> <code> >>> echo strlen($_POST["comments"])."<br />"; //WORKS >>> >>> $commments = $_POST["comments"]; // WORKS but not needed; done elsewhere >>> too. >>> >>> // echo strlen($comments); // GETS Notice: Undefined variable: comments >>> in C:\xampp\htdocs... and nothing displays. >>> >>> echo $_POST["comments"]; // WORKS >>> //echo $comments; // GETS Notice: Undefined variable: comments in C >>> ... and nothing displays. >>> >>> </code> >>> =================== > ... >> >> As others have commented on, not showing us the full code makes it very >> hard to help. The error message you are quoting says that the variable >> does NOT at that point have a value assigned to it. > > No, and I doubt anyone would go thru 500 lines of code even if I were > allowed to post it. > That said, the snippet above is ONE snippet of consecutive code lines; > they are not simply gathered into one place; That's the precise order > they occur in. > The first step of reporting such a problem is to reduce your problem to a simple case that demonstrates the issue. It seemed that you had done that, but never gave us the code. For example, the above code is NOT a piece of code that demonstrates the problem, since the line reported as generating the NOTICE has been commented out. As pointed out else-thread, the problem was a typo, but since you clearly weren't showing all thoe code (from things like the comment of being done elsewhere), we could not tell if that same typo was done THERE.
[toc] | [prev] | [next] | [standalone]
| From | Richard Yates <richard@yatesguitar.com> |
|---|---|
| Date | 2013-09-21 14:29 -0700 |
| Message-ID | <8t3s39tcmb842b3dkpa8fja7qqdvfqvieq@4ax.com> |
| In reply to | #10821 |
On Sat, 21 Sep 2013 16:20:49 -0400, Twayne <nobody@spamcop.net> wrote: Probably those three Ms in '$commments' >Hi, > >Obviously, the issue is around the comments var. It works, but it >doesn't and I'm hoping someone can explain why. > >Both echo strlen($comments); and echo $comments; throw a Notice >about an undefined variable. But the variable "comments" HAS to have >been defined in order for the two echo statements to work! > The variable 'comments' is also in SESSION data, which will also get >the same Notice of an undefined variable. > >What the heck am I missing? Why do I get the undefined var in those two >statements? > >=================== ><code> >echo strlen($_POST["comments"])."<br />"; //WORKS > >$commments = $_POST["comments"]; // WORKS but not needed; done elsewhere >too. > >// echo strlen($comments); // GETS Notice: Undefined variable: comments >in C:\xampp\htdocs... and nothing displays. > >echo $_POST["comments"]; // WORKS >//echo $comments; // GETS Notice: Undefined variable: comments in C >... and nothing displays. > ></code> >=================== > >I'm obviously missing something here since it appears the var is set >according to the 2 statements that do display what I expected. Can you >straighten me out? I've had this happen before with other vars and it's >always confusing. > >TIA, > >Twayne` >
[toc] | [prev] | [next] | [standalone]
| From | Twayne <nobody@spamcop.net> |
|---|---|
| Date | 2013-09-22 16:54 -0400 |
| Message-ID | <l1nlen$gdr$1@speranza.aioe.org> |
| In reply to | #10826 |
On 2013-09-21 5:29 PM, Richard Yates wrote: > On Sat, 21 Sep 2013 16:20:49 -0400, Twayne <nobody@spamcop.net> wrote: > > Probably those three Ms in '$commments' 3 M's? You're kidding!! I'd love to think that's a typo, but ... I pasted, not copied, the code, sooo ... Ohh, I might be about to feel so stoopid! You know, I still didn't see it even after you pointed it out! Had to use Find to see it! Damn! I'm going to owe you bigtime if that's all it is! :( I'll let ya know! Twayne` > > >> Hi, >> >> Obviously, the issue is around the comments var. It works, but it >> doesn't and I'm hoping someone can explain why. >> >> Both echo strlen($comments); and echo $comments; throw a Notice >> about an undefined variable. But the variable "comments" HAS to have >> been defined in order for the two echo statements to work! >> The variable 'comments' is also in SESSION data, which will also get >> the same Notice of an undefined variable. >> >> What the heck am I missing? Why do I get the undefined var in those two >> statements? >> >> =================== >> <code> >> echo strlen($_POST["comments"])."<br />"; //WORKS >> >> $commments = $_POST["comments"]; // WORKS but not needed; done elsewhere >> too. >> >> // echo strlen($comments); // GETS Notice: Undefined variable: comments >> in C:\xampp\htdocs... and nothing displays. >> >> echo $_POST["comments"]; // WORKS >> //echo $comments; // GETS Notice: Undefined variable: comments in C >> ... and nothing displays. >> >> </code> >> =================== >> >> I'm obviously missing something here since it appears the var is set >> according to the 2 statements that do display what I expected. Can you >> straighten me out? I've had this happen before with other vars and it's >> always confusing. >> >> TIA, >> >> Twayne` >>
[toc] | [prev] | [next] | [standalone]
| From | Twayne <nobody@spamcop.net> |
|---|---|
| Date | 2013-09-22 17:19 -0400 |
| Message-ID | <l1nmsg$k7e$1@speranza.aioe.org> |
| In reply to | #10826 |
On 2013-09-21 5:29 PM, Richard Yates wrote:
> On Sat, 21 Sep 2013 16:20:49 -0400, Twayne <nobody@spamcop.net> wrote:
>
> Probably those three Ms in '$commments'
CRAP!! I can't tell you how many times I looked at that code and didn't
see it!
But, that's all it took was to spell the var correctly, of course. I
am severely humbled and owe you a drink at the local bar were it
possible, or some other thing you'd appreciate if you're not a drinker!
Any chance you live in far upstate NY?
Regards,
Twayne`
>
>
>> Hi,
>>
>> Obviously, the issue is around the comments var. It works, but it
>> doesn't and I'm hoping someone can explain why.
>>
>> Both echo strlen($comments); and echo $comments; throw a Notice
>> about an undefined variable. But the variable "comments" HAS to have
>> been defined in order for the two echo statements to work!
>> The variable 'comments' is also in SESSION data, which will also get
>> the same Notice of an undefined variable.
>>
>> What the heck am I missing? Why do I get the undefined var in those two
>> statements?
>>
>> ===================
>> <code>
>> echo strlen($_POST["comments"])."<br />"; //WORKS
>>
>> $commments = $_POST["comments"]; // WORKS but not needed; done elsewhere
>> too.
>>
>> // echo strlen($comments); // GETS Notice: Undefined variable: comments
>> in C:\xampp\htdocs... and nothing displays.
>>
>> echo $_POST["comments"]; // WORKS
>> //echo $comments; // GETS Notice: Undefined variable: comments in C
>> ... and nothing displays.
>>
>> </code>
>> ===================
>>
>> I'm obviously missing something here since it appears the var is set
>> according to the 2 statements that do display what I expected. Can you
>> straighten me out? I've had this happen before with other vars and it's
>> always confusing.
>>
>> TIA,
>>
>> Twayne`
>>
[toc] | [prev] | [next] | [standalone]
| From | Richard Yates <richard@yatesguitar.com> |
|---|---|
| Date | 2013-09-22 14:39 -0700 |
| Message-ID | <vlou39dr62jebnpn3cqd9ttojoahhcvi4t@4ax.com> |
| In reply to | #10833 |
On Sun, 22 Sep 2013 17:19:13 -0400, Twayne <nobody@spamcop.net> wrote: >On 2013-09-21 5:29 PM, Richard Yates wrote: >> On Sat, 21 Sep 2013 16:20:49 -0400, Twayne <nobody@spamcop.net> wrote: >> >> Probably those three Ms in '$commments' > >CRAP!! I can't tell you how many times I looked at that code and didn't >see it! > But, that's all it took was to spell the var correctly, of course. I >am severely humbled and owe you a drink at the local bar were it >possible, or some other thing you'd appreciate if you're not a drinker! > Any chance you live in far upstate NY? No, Salem, Oregon. But my sister and brother live in Ithaca. Things like those 3 Ms can be very hard to see. We see what we expect. Music copyists sometimes work with score and copy upside down to minimize faulty assumptions. Probably doesn't work with php though (and its hard on the monitor stand).
[toc] | [prev] | [next] | [standalone]
| From | Twayne <nobody@spamcop.net> |
|---|---|
| Date | 2013-09-23 19:54 -0400 |
| Message-ID | <l1qkb9$a3c$1@speranza.aioe.org> |
| In reply to | #10834 |
On 2013-09-22 5:39 PM, Richard Yates wrote:
> On Sun, 22 Sep 2013 17:19:13 -0400, Twayne <nobody@spamcop.net> wrote:
>
>> On 2013-09-21 5:29 PM, Richard Yates wrote:
>>> On Sat, 21 Sep 2013 16:20:49 -0400, Twayne <nobody@spamcop.net> wrote:
>>>
>>> Probably those three Ms in '$commments'
>>
>> CRAP!! I can't tell you how many times I looked at that code and didn't
>> see it!
>> But, that's all it took was to spell the var correctly, of course. I
>> am severely humbled and owe you a drink at the local bar were it
>> possible, or some other thing you'd appreciate if you're not a drinker!
>> Any chance you live in far upstate NY?
>
> No, Salem, Oregon. But my sister and brother live in Ithaca.
>
> Things like those 3 Ms can be very hard to see. We see what we expect.
> Music copyists sometimes work with score and copy upside down to
> minimize faulty assumptions. Probably doesn't work with php though
> (and its hard on the monitor stand).
>
Well, I could rotate my display 180 easily enough - but I'm not Russian
so upside reading isn't exactly second nature! :)
I think one solution is going to be to look for a better font to use;
one that's more readable or something that sports a real time spelling
dic. Verdana helped a little to see that sort of thing but I think there
are better ones. I'd like one that slashes zero, makes I and L and l
easily distinguishable and perhaps a little wider spacing. Verdana is a
start, but it doesn't do well with lower case letters; thus the need for
a wider letter spacing.
I sort of dread going thru the zillions of fonts available, but ...
it might be worth the trouble.
Sorry; didn't mean to wax philosophical there!
See ya 'round!
Twayne`
[toc] | [prev] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2013-09-21 23:55 +0200 |
| Message-ID | <ba6iumFqfo0U1@mid.individual.net> |
| In reply to | #10821 |
On 21/09/13 22:20, Twayne wrote:
> Hi,
>
> Obviously, the issue is around the comments var. It works, but it
> doesn't and I'm hoping someone can explain why.
>
> Both echo strlen($comments); and echo $comments; throw a Notice
> about an undefined variable. But the variable "comments" HAS to have
> been defined in order for the two echo statements to work!
> The variable 'comments' is also in SESSION data, which will also get
> the same Notice of an undefined variable.
>
> What the heck am I missing? Why do I get the undefined var in those two
> statements?
>
> ===================
> <code>
> echo strlen($_POST["comments"])."<br />"; //WORKS
>
> $commments = $_POST["comments"]; // WORKS but not needed; done elsewhere
> too.
Assuming this is just a typo and it was supposed to be $comment
> // echo strlen($comments); // GETS Notice: Undefined variable: comments
> in C:\xampp\htdocs... and nothing displays.
Variables ain't super global, with other words if you do something
inside a function it will not automatically be the same outside the function
$comment = "q";
function b() {
$comment = "b";
}
b();
echo $comment;
This will result in "q" and not "b", as the $comment inside the function
is another than the one outside the function.
just to clarify, values will not magically get into functions
$comment = "q";
function b() {
echo $comment;
}
b();
this will return an empty output (logging undefined variable).
There is a few exception from this, super global variable is one of
those, like $_POST, $_GET, $_SESSION and so on, thos can be accessed
anywhere in your code.
You can use global in a function to access variable set outside a
function (this is really bad coding and you will most likely get in bad
trouble, so avoid using it).
--
//Aho
[toc] | [prev] | [next] | [standalone]
| From | Twayne <nobody@spamcop.net> |
|---|---|
| Date | 2013-09-22 16:57 -0400 |
| Message-ID | <l1nlk4$gdr$2@speranza.aioe.org> |
| In reply to | #10827 |
On 2013-09-21 5:55 PM, J.O. Aho wrote:
> On 21/09/13 22:20, Twayne wrote:
...
>>
>> ===================
>> <code>
>> echo strlen($_POST["comments"])."<br />"; //WORKS
>>
>> $commments = $_POST["comments"]; // WORKS but not needed; done elsewhere
>> too.
>
> Assuming this is just a typo and it was supposed to be $comment
>
>> // echo strlen($comments); // GETS Notice: Undefined variable: comments
>> in C:\xampp\htdocs... and nothing displays.
>
> Variables ain't super global, with other words if you do something
> inside a function it will not automatically be the same outside the
> function
>
> $comment = "q";
>
> function b() {
> $comment = "b";
> }
>
> b();
>
> echo $comment;
>
> This will result in "q" and not "b", as the $comment inside the function
> is another than the one outside the function.
>
> just to clarify, values will not magically get into functions
>
> $comment = "q";
>
> function b() {
> echo $comment;
> }
>
> b();
>
> this will return an empty output (logging undefined variable).
>
>
> There is a few exception from this, super global variable is one of
> those, like $_POST, $_GET, $_SESSION and so on, thos can be accessed
> anywhere in your code.
>
> You can use global in a function to access variable set outside a
> function (this is really bad coding and you will most likely get in bad
> trouble, so avoid using it).
>
Good advice; thanks.
Twayne`
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web