Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #12880
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Declaring an array necessary? |
| Date | 2014-02-21 15:48 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <le8e2d$m9r$1@dont-email.me> (permalink) |
| References | <le840m$8kk$1@news.albasani.net> <5307b154$0$9525$9b4e6d93@newsspool1.arcor-online.net> |
On 2/21/2014 3:04 PM, Christian Stadler wrote:
> Am 21.02.2014 18:56, schrieb The Natural Philosopher:
>> I was just wondering. Php assumes a varibale exists as soon as it is
>> assigned a value, but a function exists to create an array..
>> Sop can one just say
>>
>> $arr['hello']='sexy';
>>
>> or should there be
>>
>> $arr=array();
>>
>> first?
>
> Its generally a good idea to initialize a variable, before you change
> its contents, unless you are 100% sure, that the variable hasn't been
> initialized elsewhere or probably through whatever exploit and so on.
> But honestly: Can you be 100% sure? ;-)
>
> Another (quick and dirty) example would be :
>
> | $tablecontents = '';
> | foreach ($foo AS $bar => $moo) {
> | $tablecontents .= "\t<tr><td>$bar</td><td>$moo</td></tr>\n";
> | }
> | echo "<table>\n$tablecontents</table>\n";
>
> If you leave $tablecontents = ''; away, this could result in unwanted
> behaviour up to something even worse, like XSS-attacks.
>
> PS: If someone can explain this in a better way, feel free to do so. But
> please don't tell me, whats wrong in my post. Its just a quick and dirty
> example and probably not the best way to explain this. But right now,
> I'm not in the mood to recherche for hours and hours to ensure, that
> every single letter I type in a *.c.l.php-group is 100% correct ...
>
> Regards,
> Christian Stadler
>
Christian,
Nope, nothing wrong with your post. And I agree - it is almost always a
good idea to initialize a variable before using it.
How many times have you seen in this group NOTIFY messages being turned
off and/or ignored - then people complaining because the code doesn't
work as expected?
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Declaring an array necessary? The Natural Philosopher <tnp@invalid.invalid> - 2014-02-21 17:56 +0000
Re: Declaring an array necessary? Christian Stadler <stadli@gmx.de> - 2014-02-21 21:04 +0100
Re: Declaring an array necessary? Jerry Stuckle <jstucklex@attglobal.net> - 2014-02-21 15:48 -0500
Re: Declaring an array necessary? The Natural Philosopher <tnp@invalid.invalid> - 2014-02-21 21:32 +0000
Re: Declaring an array necessary? Gregor Kofler <usenet@gregorkofler.com> - 2014-02-21 22:55 +0100
Re: Declaring an array necessary? Tim Streater <timstreater@greenbee.net> - 2014-02-21 22:06 +0000
Re: Declaring an array necessary? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2014-02-21 22:58 +0100
Re: Declaring an array necessary? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2014-02-21 14:03 -0800
csiph-web