Re: Where to declare Variables



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Scott Johnson wrote:
In most of my code I have used a scheme as follows.

I have a displayable page with a form.

To minimize the actual php code on this page I include all the
processing code in an included file.

On the form page, the input fields have php variables to display the
data entered if another field failed validation such as:

<input name="summary" type="text" value="<?php echo $summary;?>"/>

Now to prevent notice warning for the variable I set it in the
'included' file:

$summary = '';

Now is this a good way to do this, or is it wiser to do the declaration
in the top of the form page? Where do y'all usually do your
declarations for form value variables?

The reason this came to mind is that in using Zend IDE, it does not
recognize the variables set in an included file if it is used in a
different file and I get warnings about an variable being used before it
is declared. If I declare it at the top of the file it is used the
warning goes away.

I just want to make sure that this just may be a limitation of the IDE
or it is pointing at a good practice.

Thanks




Hello,

first it is a good practice to declare the variables before using them.

The problem you describe sounds like a Zend IDE problem.
If you really want to make sure you code does not have any warnings or notices
(which is very good) have a look here:

http://www.php.net/manual/en/function.error-reporting.php

then execute your code in the browser or console and check the error messages there.

j.keßler
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkn/174ACgkQE++2Zdc7EtcbngCfa4cOB610og4kSmq2etOImnsu
mfAAoImoagnbHHFcTnbb+3hO5BATAAEM
=0rWh
-----END PGP SIGNATURE-----
.



Relevant Pages

  • Re: Where to declare Variables
    ... the input fields have php variables to display the ... Now to prevent notice warning for the variable I set it in the ... first it is a good practice to declare the variables before using them. ... The problem you describe sounds like a Zend IDE problem. ...
    (comp.lang.php)
  • Re: Where to declare Variables
    ... the input fields have php variables to display the ... Now to prevent notice warning for the variable I set it in the ... first it is a good practice to declare the variables before using them. ... The problem you describe sounds like a Zend IDE problem. ...
    (comp.lang.php)
  • Where to declare Variables
    ... To minimize the actual php code on this page I include all the processing code in an included file. ... the input fields have php variables to display the data entered if another field failed validation such as: ... Now is this a good way to do this, or is it wiser to do the declaration in the top of the form page? ... If I declare it at the top of the file it is used the warning goes away. ...
    (comp.lang.php)
  • Re: Interactive `setq, redux
    ... | ridiculous, IMO, that one can't use `setq' in this way. ... and one line of warning when using the ... warning, but declare the variable special, along the lines of: "Warning: ... The debate seems to center around the "newbie experience". ...
    (comp.lang.lisp)
  • Re: help urgent
    ... Declare a dynamic array of stuctures. ... > in the event handler should display an OpenFileDialog allowing the user ... load the date from each array member into the combo box. ...
    (microsoft.public.vb.general.discussion)