Hallo,

Hier is een php script een class en een index bestand. Het is een teller, maar hij echo nix in de browser.
Wil iemand mij helpen en vertellen waar de fout inzit?

alvast bedankt.

index:

<?php
require_once ("count_class.php");
$teller = new Teller();
$teller = setStand(100);
$teller->ophogen();
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
	<title></title>
	
</head>

<body>
<?php
	echo "de stand is" . $teller->getStand();
?>
</body>
</html>



class:

<?php
class Teller{

	public $stand=1;
	
	
	
	public function ophogen(){
		$this->stand++;
	}
	
	public function __construct($stand=0){
		$this->stand=$stand;
	}
	
	public function getStand(){
		return $this->stand;
	}
	
	public function setStand($nieuweStand){
		$this->stand=$nieuweStand;
	}

}

?>

Het gaat fout bij het aanroepen van de methode setStand():
[code lang=php]
$teller = new Teller();
$teller = setStand(100);
[/code]
Je moet hier -> gebruiken:
[code lang=php]
$teller = new Teller();
$teller->setStand(100);
[/code]
Klopt, nu overschrijf je de instantie $teller met het object.

Reageren