0

I receive a lot of undefined variable errors in zend studio 10.

I have a php file like this :

file var.php

<?php
$functions = $root."/requires/functions.php";
$top_utf = $root."/requires/top_utf.php" ;
$database = $root."/requires/db.php" ;
$footer = $root."/requires/pageFooter.php" ;
?>

Now if I use the following code in a php file, zend studio shows Undefined Variable errors on all the require_once lines. (If I access this page with a browser the page is displayed as expected and it works perfectly.)

<?php
$root = $_SERVER['DOCUMENT_ROOT'];
require_once($root."/requires/vars.php") ;
require_once($functions);
require_once($top_utf);
require_once($database);
require_once($footer);
?>

Doesn't Zend Studio recognize the declared variables in an included file (var.php in this case)? Since $functions and $top_utf variables are defined in var.php, I believe I shouldn't receive these errors. Any kind of advice is much appreciated.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Tera
  • 113
  • 3
  • 12

1 Answers1

0

If you're going to use this style of programming, which I'm not advocating, I suggest you define constants in your var.php instead

dualmon
  • 1,225
  • 1
  • 8
  • 16
  • thanks for trying to help. But since I'm new to php a more detailed response can help me better. I use a series of variables in all the pages(about 36). To make the php files simpler to work with, I moved the variables to a var.php file and included this file at the top of each page. Do you think it's better to have all the variables in top of all pages? Can you explain why you don't advocate this? I also defined the variables in var.php, still the main php files are filled with **Undefined Variable** errors. – Tera Aug 25 '13 at 23:54
  • sorry I tried to correct my previous comment, but it was too late. Defining the variables worked out. but still I'm eager to know why you don't advocate this type of programming (gathering all the variables in a file and including it at the top of other php files). Thanks for any further help. – Tera Aug 26 '13 at 00:10
  • Using includes like this is called procedural programming. It gets back to the roots of PHP, when it was common to use it like this. PHP is now object oriented, and makes use of namespaces and class autoloading, which have many advantages over procedural style such as your example. Since you are using Zend Studio, you might want to look at Zend Framework 2 http://framework.zend.com/manual/2.2/en/index.html – dualmon Aug 28 '13 at 04:33