FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Setting & displaying Variables
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Setting & displaying Variables [message #182870 is a reply to message #182865] Sun, 22 September 2013 20:57 Go to previous message
bill is currently offline  bill
Messages: 310
Registered: October 2010
Karma:
Senior Member
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`
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: test for file existance
Next Topic: mail working, not working.
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 13:05:15 GMT 2024

Total time taken to generate the page: 0.04050 seconds