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 #182868 is a reply to message #182862] Sun, 22 September 2013 20:47 Go to previous messageGo to previous message
bill is currently offline  bill
Messages: 310
Registered: October 2010
Karma:
Senior Member
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`
>
[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: Sat Nov 23 03:54:53 GMT 2024

Total time taken to generate the page: 0.04820 seconds