打印对象内部的对象变量

Well, ive been trying to get my crm to print multiple contacts for each company but i cant get it to work

Company is a class,companycontactis a class

//class called company

 function __construct($idklanten,$naam,$adres,$postcode,$stad,$contacten){
    $this->idklanten=$idklanten;
    $this->naam=$naam;
    $this->adres=$adres;
    $this->postcode=$postcode;
    $this->stad=$stad;
    $this->contacten=$contacten;

}

//class called contact

    function __construct($idcontactklanten,$voornaam,$tussenvoegsel,$achternaam,$tel,$email,$klantID){
    $this->idcontactklanten=$idcontactklanten;
    $this->voornaam=$voornaam;
    $this->tussenvoegsel=$tussenvoegsel;
    $this->achternaam=$achternaam;
    $this->tel=$tel;
    $this->email=$email;
    $this->klantID=$klantID;
}

//getname for a contact

  function getNaam() {
    if(strlen($this->gettussenvoegsel()) == 0) {

        return $this->getvoornaam()." ".$this->getachternaam()."";
    }
    else {


        return $this->getvoornaam() . " "  . $this->gettussenvoegsel() . " " .  $this->getachternaam();
    }
}

//function for getting the names from my object company,array with objects of contacts

 function getcontacten(){           
        $ct=$this->contacten[$teller];
        $txt="";
        for($teller=0;$teller<10;$teller++){
            $txt+=$ct->getNaam()."<br>";
        }
     return $txt;
}

then on my index page when i call getcontacten() it does not work comparing to my other get function which do work. it just outputs a 0

Any help is appreciated

Your biggest error would be the following:

$txt+=$ct->getNaam()."<br>";

Should be

$txt.=$ct->getNaam()."<br>";

Because to append to a string you use ".=", not "+=".

Also I don't know if the other part of you code works, I would write something like the following:

$txt = "";
foreach ($this->contacten as $ct){
    $txt .= $ct->getNaam() . "<br />";
}
return $txt;

or

$txt = "";
for ($i = 0; $i < count($this->contacten); $i++){
    $txt .= $this->contacten[$i]->getNaam() . "<br />";
}
return $txt;