Connecting Tech Pros Worldwide Help | Site Map

Errors in php 5.0.4 Not in 4.3.10-16

  #1  
Old September 28th, 2005, 05:55 PM
Han Koster
Guest
 
Posts: n/a
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


  #2  
Old September 28th, 2005, 07:05 PM
Jerry Stuckle
Guest
 
Posts: n/a

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
==================
  #3  
Old September 29th, 2005, 12:25 PM
Kirsten
Guest
 
Posts: n/a

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
  #4  
Old September 29th, 2005, 01:55 PM
Obvious
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
script dies yet there are no errors in error log Lawrence Krubner answers 15 October 24th, 2008 07:25 PM
problem to open a distant XML file in PHP Claire DURAND answers 4 February 16th, 2007 07:15 PM
'echo "": No such file or directory" error using "exec" to pipe in PHP script comp.lang.tcl answers 21 December 2nd, 2006 03:45 PM
Creating Gantt Chart in PHP Kuna answers 5 November 8th, 2006 12:15 PM
multidimensional array declaration in php vito answers 21 July 18th, 2006 05:35 PM