Re: how to access class members

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

 



On 4 May 2010 14:02, Alexander Schunk <aschunk@xxxxxxxxx> wrote:
> Hello,
>
> i have a question:
>
> How to access class members?
>
> I have the following class definition:
>
> class Mitarbeiter{
>
>           public $name = 'meier';
>           public $alter = '50';
>           public $gehalt = '2000';
>           public $abteilung = 'programmierung';
>
>           function printMember(){
>              echo 'Name: ' . $this->public;
>              echo 'Alter: ' . $this->public;
>              echo 'Gehalt: ' . $this->public;
>              echo 'Abteilung: ' . $this->public;
>           }
>      }
>
> Now i want to access the public member with:
>
> $m = new Mitarbeiter();
> $m->printMember();
>
> When calling method printMember() i get an error "cannot access empty
> class member".
>
> I dont see why the class members are empty?
>
> Regards
> Alexander
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

echo $this->name;

public relates to the visibility of the property (public - can be seen
by all, protected - can only be seen by this class and sub-classes and
private - can only be seen by this class).

Read more about this at
http://docs.php.net/manual/en/language.oop5.visibility.php

-- 
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux