Wat doe ik fout ?
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!DOCTYPE html>
<html>
<head>
<title>Reconstructing the Person Class</title>
<link type='text/css' rel='stylesheet' href='style.css'/>
</head>
<body>
<p>
<?php
class Person {
public $teacher;
public $student;
public $isAlive = true;
public $firstname;
public $lastname;
public $age;
public function __construct($firstname , $lastname, $age) {
$this->firstname = $firstname;
$this->lastname = $lastname;
$this->age = $age;
}
}
$teacher = new Person(true , "Henk" , "Barkhof" , 65);
$student = new Person(true , "Inge" , "Franzen" , 50);
[b] echo $teacher->??;
//echo $age->??;
[/b] ;
?>
</p>
</body>
</html>
<html>
<head>
<title>Reconstructing the Person Class</title>
<link type='text/css' rel='stylesheet' href='style.css'/>
</head>
<body>
<p>
<?php
class Person {
public $teacher;
public $student;
public $isAlive = true;
public $firstname;
public $lastname;
public $age;
public function __construct($firstname , $lastname, $age) {
$this->firstname = $firstname;
$this->lastname = $lastname;
$this->age = $age;
}
}
$teacher = new Person(true , "Henk" , "Barkhof" , 65);
$student = new Person(true , "Inge" , "Franzen" , 50);
[b] echo $teacher->??;
//echo $age->??;
[/b] ;
?>
</p>
</body>
</html>
Graag in het vervolg bij code, [code] [/code] tags gebruiken.[/modedit]
Gewijzigd op 17/01/2015 16:47:26 door Bas IJzelendoorn
Directe toegang tot public properties vervangen we vaak echter liever door een getter. Voor de volledige naam bijvoorbeeld:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
class Person
{
private $teacher;
private $student;
private $isAlive = true;
private $firstname;
private $lastname;
private $age;
public function __construct($firstname , $lastname, $age)
{
$this->firstname = $firstname;
$this->lastname = $lastname;
$this->age = $age;
}
public function getName()
{
return $this->firstname . ' ' . $this->lastname;
}
}
?>
class Person
{
private $teacher;
private $student;
private $isAlive = true;
private $firstname;
private $lastname;
private $age;
public function __construct($firstname , $lastname, $age)
{
$this->firstname = $firstname;
$this->lastname = $lastname;
$this->age = $age;
}
public function getName()
{
return $this->firstname . ' ' . $this->lastname;
}
}
?>
Even aanvullend ... het is niet de bedoeling om classes in HTML pagina's te integreren.
De aanvullende opmerkingen begrijp ik (nog) niet. Begin net php te leren.
Toevoeging op 17/01/2015 18:04:17:
Hartelijk dank. Ga het uit proberen.
De aanvullende opmerkingen begrijp ik (nog) niet. Begin net php te leren.