|
Posted by jmark on 05/17/07 11:58
On May 16, 1:17 pm, Erwin Moller
<since_humans_read_this_I_am_spammed_too_m...@spamyourself.com> wrote:
> j...@fastermail.com wrote:
> > I have seen some code like
> > $value = strval($REQUEST['value']);
>
> > I would like to know what is the use of strval here since $_REQUEST
> > values are strings?
>
> Hi,
>
> $_REQUEST values might as well contain arrays.
>
> Consider this form:
> <form action="test.php" Method="POST">
> <input type="checkbox" name="bla[]" value="1">1<br>
> <input type="checkbox" name="bla[]" value="2">2<br>
> <input type="checkbox" name="bla[]" value="3">3<br>
> </form>
>
> When receiving $_POST["bla"] it contains an array.
>
> The programmer wanted to make sure it is a string.
>
> Regards,
> Erwin Moller
>
> PS: I think you should avoid $_REQUEST. Just use $_POST and $_GET.
strval works only on scalar values. Using it on arrays has no effect.
is_string() should be the function to be used to determine if a value
is string. strval just casts values into strings. Casting a string
into a string is meaningless.
There are some instances where $_REQUEST can be more convenient than
using $_POST and $_GET like for example where you have a script that
is called by either get or post method
Navigation:
[Reply to this message]
|