Re: Where to declare Variables



Scott Johnson schreef:
j.keßler wrote:
-----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-----

I had a strong idea that it was an IDE shortcoming. As you said I always declare my variables prior to use, it was just where to declare them. Since I don't do design work, only the function coding, I like to minimize code in the displayable page. This way if the design guy changes stuff, he does not have to worry about breaking or integrating a bunch of lines of code.

Are you sure you created a project and added all the used files to that project?
If you just use Zend IDE without a project context, it will only syntax highlight and make suggestions for functionnames and such.

Regards,
Erwin Moller


Thanks



--
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
.



Relevant Pages

  • Re: Where to declare Variables
    ... To minimize the actual php code on this page I include all the ... 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. ...
    (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)
  • 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)
  • Re: how can I find out all the unused functions?
    ... > int Nouse(); ... There's no reason to issue a warning for the above code (at least not ... It's also better to declare ...
    (comp.lang.c)