Re: [PHP] Classes and access to outside variables



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@xxxxxxxxxxx>:

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




Relevant Pages

  • Re: Constructors And Exceptions
    ... > upon the execution of the destructor. ... > signaling constructor failure via the exception mechanism. ... > My initial reaction to the first book was that the practice is not dubious ...
    (comp.lang.cpp)
  • Re: Declaring many objects
    ... Yes, I would certainly provide such a constructor in practice, but it is ... reasonable text to refer to. ... Francis Glassborow ACCU ...
    (alt.comp.lang.learn.c-cpp)
  • Re: reasons to hate C#
    ... That's bunk. ... To clarify the constructor chaining problem; in C#, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Declaring many objects
    ... > Yes, I would certainly provide such a constructor in practice, but it is ... > agree that hard coding it into the program is not good practice). ... I've no shortage of reference material but the problem can ... clear idea of what you want to accomplish but no clear idea ...
    (alt.comp.lang.learn.c-cpp)