Connecting Tech Pros Worldwide Forums | Help | Site Map

Errors in php 5.0.4 Not in 4.3.10-16

Han Koster
Guest
 
Posts: n/a
#1: Sep 28 '05
I use the following statements:

$var = "";
$var = $_POST('varname');

In php 4, when 'varname' was not defined, $var remained an empty string;
In php 5, I suddenly get errors.

I solved these by including the function array_key_exist to check the
occurence of 'varname'
Is this the prefered way or is ther a better solution?

Thanx,
Han koster



Jerry Stuckle
Guest
 
Posts: n/a
#2: Sep 28 '05

re: Errors in php 5.0.4 Not in 4.3.10-16


Han Koster wrote:[color=blue]
> I use the following statements:
>
> $var = "";
> $var = $_POST('varname');
>
> In php 4, when 'varname' was not defined, $var remained an empty string;
> In php 5, I suddenly get errors.
>
> I solved these by including the function array_key_exist to check the
> occurence of 'varname'
> Is this the prefered way or is ther a better solution?
>
> Thanx,
> Han koster
>
>[/color]

Han,

You might have had display errors turned off in PHP 4.

It's always good to see if something exists before trying to use it. I
use isset($_POST['varname']), but I'm sure array_key_exist will work
just fine.

My code looks something like:

$var = isset($_POST['varname']) ? $_POST['varname'] : 'default_value';

That way I can set a default - even if it is null.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Kirsten
Guest
 
Posts: n/a
#3: Sep 29 '05

re: Errors in php 5.0.4 Not in 4.3.10-16


Han Koster schrieb:[color=blue]
> I use the following statements:
>
> $var = "";
> $var = $_POST('varname');
>
> In php 4, when 'varname' was not defined, $var remained an empty string;
> In php 5, I suddenly get errors.
>
> I solved these by including the function array_key_exist to check the
> occurence of 'varname'
> Is this the prefered way or is ther a better solution?
>
> Thanx,
> Han koster
>
>[/color]
Did you get an error or a notice?
It is neccessary in PHP 5 to declare variables before use them.

-Kirsten
Obvious
Guest
 
Posts: n/a
#4: Sep 29 '05

re: Errors in php 5.0.4 Not in 4.3.10-16


On Thu, 29 Sep 2005 13:18:54 +0200, Kirsten wrote:
[color=blue]
> Did you get an error or a notice?
> It is neccessary in PHP 5 to declare variables before use them.[/color]

Are you sure about that?
Closed Thread