Re: Classes and access to outside variables

From: Date: Sat, 29 Sep 2007 12:18:28 +0000
Subject: Re: Classes and access to outside variables
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-262576@lists.php.net to get a copy of this message
Refer to the global on the constructor. Anyway, using a global like that is not a good practice. Just pass the variable to the constructor. 2007/9/29, Merlin <ngroups@fastmail.fm>: > > Hi there, > > I am new to PHP classes and I do want to access a variable outside the > class, but somehow that does not work. global also does not have any > effect. > > In the following example I would like to be able to access $dbh from > inside the class like I did in that example. This does not work. Can > somebody please give me a hint on the right syntax? > > $dbh = 'test'; > > class search_helper extends AjaxACApplication > { > /** > * Database connection details > */ > > var $db_hostname = $dbh; > > Thank you for any help, > > Merlin > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#262576) next »