Re: Classes and access to outside variables

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

 



Merlin,

if you are using php5 the var keyword is no longer valid; that was used in
classes in php4.
if you want to structure your classes properly you need to study PPP
(public, private, protected) access modifiers.
typically member variables are declared to be private or protected, if there
will be child
objects that will access them directly.  to provide access to said member
variables
creates public method.  public methods are visible to external code and have
access to the
private members, be they variables or methods.

-nathan

On 9/29/07, Merlin <ngroups@xxxxxxxxxxx> wrote:
>
> 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
>
>

[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