Scope of Variables and use of global and this->var

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is just a general question,

I am not 100% on when to use global $var , and $this->var  and how/what
about the GLOBAL vars ....

Lets say I have one file I  call config.php ....here I connect to the db, to
ldap etc .... the connection "var" I can then use in a file on its own ...
obviously after I include "config.php"  .... lets say in config.php my DB
connect was $dbconnect ....

In my index.php page I then use $dbconnect again .... but do I simply use
$dbconnect again ... or must I say global $dbconnect and then use it in the
rest of the DB calls? or use GLOBALS .. Within a class I can use $this->var
correct ... but its not something to be used in a basic "procedural" if I
can call it that page...


Lets say with my config.php and its connection to the db ...where I have
$dbconnect ...... in a class I can also use it, do I access  this var
straight as $dbconnect or use $this->dbconnect = $dbconnect (and define it
as global $dbconnect first before doing this)

I am getting my results and seems to working most of the time, but not sure
if I am using calls to global or $this->var ..when its not required and
calling the var direct would of sufficed.

I have never really used GLOBAL vars, so not sure how this ties in or if it
might be even more helpful ...

Some suggestions or pointers or examples would be appreciated just to clear
up some confusion.


Regards

Oh and if one class uses methods in another class .... do I instansiate a
new object of the other class .... I have seen use of OtherClass::Method
....  is this better method of $obj = new OtherClass()  use

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux