Sevvlor schreef:Nice!
Het Wat heb jij vandaag geprogrammeerd? topic
Me eerst OOP class!
Codeblok (voorbeeld.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class dbconnection extends Mysqli {
public function __construct($host, $user, $pass, $db) {
parent::__construct($host, $user, $pass, $db);
if(mysqli_connect_error()) {
die("Kan niet met de database van Livetrein verbinden. Probeer het over enkele momenten weer!");
}
}
}
class info {
public $station;
public function __construct($username, $password, $station) {
$this->Station = $station;
$this->Username = $username;
$this->Password = $password;
$this->Connection = new dbconnection("localhost", "root", "", "livetrein");
}
public function convert($method = code) {
$result = mysqli_query($this->Connection, "
SELECT ".$method."
FROM station
WHERE fullname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR midname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR smallname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR code =
".mysqli_real_escape_string($this->Connection, $this->Station)."
AND land =
NL
LIMIT
1");
if($result) {
$result = $result->fetch_assoc();
return $result[$method];
} else {
return false;
}
}
}
$info = new info(, , Amsterdam Centraal);
echo $info->convert(); //output ASD
?>
Ik weet het, geen snippets posten alleen dit is mijn eerste class en wil er eigenlijks wel een feedback op!
Codeblok (voorbeeld.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class dbconnection extends Mysqli {
public function __construct($host, $user, $pass, $db) {
parent::__construct($host, $user, $pass, $db);
if(mysqli_connect_error()) {
die("Kan niet met de database van Livetrein verbinden. Probeer het over enkele momenten weer!");
}
}
}
class info {
public $station;
public function __construct($username, $password, $station) {
$this->Station = $station;
$this->Username = $username;
$this->Password = $password;
$this->Connection = new dbconnection("localhost", "root", "", "livetrein");
}
public function convert($method = code) {
$result = mysqli_query($this->Connection, "
SELECT ".$method."
FROM station
WHERE fullname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR midname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR smallname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR code =
".mysqli_real_escape_string($this->Connection, $this->Station)."
AND land =
NL
LIMIT
1");
if($result) {
$result = $result->fetch_assoc();
return $result[$method];
} else {
return false;
}
}
}
$info = new info(, , Amsterdam Centraal);
echo $info->convert(); //output ASD
?>
Ik weet het, geen snippets posten alleen dit is mijn eerste class en wil er eigenlijks wel een feedback op!
Lees de tutorial over OOP nog eens door op phptuts.nl en houd je aan de php standaarden.
Dylanh schreef:Codeblok (voorbeeld.php):Me eerst OOP class!
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class dbconnection extends Mysqli {
public function __construct($host, $user, $pass, $db) {
parent::__construct($host, $user, $pass, $db);
if(mysqli_connect_error()) {
die("Kan niet met de database van Livetrein verbinden. Probeer het over enkele momenten weer!");
}
}
}
class info {
public $station;
public function __construct($username, $password, $station) {
$this->Station = $station;
$this->Username = $username;
$this->Password = $password;
$this->Connection = new dbconnection("localhost", "root", "", "livetrein");
}
public function convert($method = code) {
$result = mysqli_query($this->Connection, "
SELECT ".$method."
FROM station
WHERE fullname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR midname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR smallname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR code =
".mysqli_real_escape_string($this->Connection, $this->Station)."
AND land =
NL
LIMIT
1");
if($result) {
$result = $result->fetch_assoc();
return $result[$method];
} else {
return false;
}
}
}
$info = new info(, , Amsterdam Centraal);
echo $info->convert(); //output ASD
?>
Ik weet het, geen snippets posten alleen dit is mijn eerste class en wil er eigenlijks wel een feedback op!
CLASSEN != OOP

Wanneer leren mensen dit nou eens.
Rik schreef:1Codeblok (voorbeeld.php):Eerdere citaten tonen
Dylanh schreef:Me eerst OOP class!
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class dbconnection extends Mysqli {
public function __construct($host, $user, $pass, $db) {
parent::__construct($host, $user, $pass, $db);
if(mysqli_connect_error()) {
die("Kan niet met de database van Livetrein verbinden. Probeer het over enkele momenten weer!");
}
}
}
class info {
public $station;
public function __construct($username, $password, $station) {
$this->Station = $station;
$this->Username = $username;
$this->Password = $password;
$this->Connection = new dbconnection("localhost", "root", "", "livetrein");
}
public function convert($method = code) {
$result = mysqli_query($this->Connection, "
SELECT ".$method."
FROM station
WHERE fullname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR midname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR smallname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR code =
".mysqli_real_escape_string($this->Connection, $this->Station)."
AND land =
NL
LIMIT
1");
if($result) {
$result = $result->fetch_assoc();
return $result[$method];
} else {
return false;
}
}
}
$info = new info(, , Amsterdam Centraal);
echo $info->convert(); //output ASD
?>
Ik weet het, geen snippets posten alleen dit is mijn eerste class en wil er eigenlijks wel een feedback op!
CLASSEN != OOP

Wanneer leren mensen dit nou eens.
PHP.net zegt dat clases wel OOP zijn.
Poedeltje schreef:Ik weet het, geen snippets posten alleen dit is mijn eerste class en wil er eigenlijks wel een feedback op!1Eerdere citaten tonen
Rik schreef:Codeblok (voorbeeld.php):Eerdere citaten tonen
Dylanh schreef:Me eerst OOP class!
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class dbconnection extends Mysqli {
public function __construct($host, $user, $pass, $db) {
parent::__construct($host, $user, $pass, $db);
if(mysqli_connect_error()) {
die("Kan niet met de database van Livetrein verbinden. Probeer het over enkele momenten weer!");
}
}
}
class info {
public $station;
public function __construct($username, $password, $station) {
$this->Station = $station;
$this->Username = $username;
$this->Password = $password;
$this->Connection = new dbconnection("localhost", "root", "", "livetrein");
}
public function convert($method = code) {
$result = mysqli_query($this->Connection, "
SELECT ".$method."
FROM station
WHERE fullname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR midname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR smallname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR code =
".mysqli_real_escape_string($this->Connection, $this->Station)."
AND land =
NL
LIMIT
1");
if($result) {
$result = $result->fetch_assoc();
return $result[$method];
} else {
return false;
}
}
}
$info = new info(, , Amsterdam Centraal);
echo $info->convert(); //output ASD
?>
CLASSEN != OOP

Wanneer leren mensen dit nou eens.
PHP.net zegt dat clases wel OOP zijn.
Link?
OOP = classen
classen != OOP
Oop zijntoch objecten? $Mysqli->query(); etc?
Dylanh schreef:OOP = Object-oriented programmingOop zijntoch objecten? $Mysqli->query(); etc?
Volg eens wat tutorials naar OOP dan zie je de logica er na een tijd wel van in.
Poedeltje schreef:Ik weet het, geen snippets posten alleen dit is mijn eerste class en wil er eigenlijks wel een feedback op!1Eerdere citaten tonen
Rik schreef:Codeblok (voorbeeld.php):Eerdere citaten tonen
Dylanh schreef:Me eerst OOP class!
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class dbconnection extends Mysqli {
public function __construct($host, $user, $pass, $db) {
parent::__construct($host, $user, $pass, $db);
if(mysqli_connect_error()) {
die("Kan niet met de database van Livetrein verbinden. Probeer het over enkele momenten weer!");
}
}
}
class info {
public $station;
public function __construct($username, $password, $station) {
$this->Station = $station;
$this->Username = $username;
$this->Password = $password;
$this->Connection = new dbconnection("localhost", "root", "", "livetrein");
}
public function convert($method = code) {
$result = mysqli_query($this->Connection, "
SELECT ".$method."
FROM station
WHERE fullname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR midname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR smallname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR code =
".mysqli_real_escape_string($this->Connection, $this->Station)."
AND land =
NL
LIMIT
1");
if($result) {
$result = $result->fetch_assoc();
return $result[$method];
} else {
return false;
}
}
}
$info = new info(, , Amsterdam Centraal);
echo $info->convert(); //output ASD
?>
CLASSEN != OOP

Wanneer leren mensen dit nou eens.
PHP.net zegt dat clases wel OOP zijn.
Als je OOP programmeert programmeer je met classes, maar het gebruik van classen betekend niet meteen dat je OOP programmeert.
Dylanh schreef:OOP is niet per se het gebruik van objecten, of het gebruik van classen. Want als je gebruik maakt van classen gebruik je vrijwel altijd ook objecten. Maar dat wil niet zeggen dat de objecten en de implementatie ook echt volgens het OOP-principe gedaan zijn.Oop zijntoch objecten? $Mysqli->query(); etc?
Dit beter dan?
Codeblok (voorbeeld.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class Dbconnection extends Mysqli {
public function __construct($host, $user, $pass, $db) {
parent::__construct($host, $user, $pass, $db);
if(mysqli_connect_error()) {
die("Kan niet met de database van Livetrein verbinden. Probeer het over enkele momenten weer, exuses voor het ongemak.");
}
}
}
class Info {
public $station;
protected $username;
protected $password;
private $data;
private $method;
private $assoc;
public function __construct($username, $password) {
$this->Username = $username;
$this->Password = $password;
$this->Connection = new Dbconnection("localhost", "root", "", "livetrein");
}
public function setStation($station) {
$this->Station = $station;
}
private function setAssoc($data) {
return $data->fetch_assoc();
}
private function returnData($assoc, $data) {
return $assoc[$data];
}
public function convert($method = "code") {
$result = mysqli_query($this->Connection, "
SELECT ".$method."
FROM station
WHERE fullname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR midname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR smallname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR code =
".mysqli_real_escape_string($this->Connection, $this->Station)."
AND land =
NL
LIMIT
1");
return $this->returnData($this->setAssoc($result), $method);
}
public function __destruct() {
$this->Connection->close();
}
}
$info = new Info(, );
$info->setStation("Amsterdam Centraal");
echo $info->convert(); // output ASD
?>
Codeblok (voorbeeld.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class Dbconnection extends Mysqli {
public function __construct($host, $user, $pass, $db) {
parent::__construct($host, $user, $pass, $db);
if(mysqli_connect_error()) {
die("Kan niet met de database van Livetrein verbinden. Probeer het over enkele momenten weer, exuses voor het ongemak.");
}
}
}
class Info {
public $station;
protected $username;
protected $password;
private $data;
private $method;
private $assoc;
public function __construct($username, $password) {
$this->Username = $username;
$this->Password = $password;
$this->Connection = new Dbconnection("localhost", "root", "", "livetrein");
}
public function setStation($station) {
$this->Station = $station;
}
private function setAssoc($data) {
return $data->fetch_assoc();
}
private function returnData($assoc, $data) {
return $assoc[$data];
}
public function convert($method = "code") {
$result = mysqli_query($this->Connection, "
SELECT ".$method."
FROM station
WHERE fullname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR midname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR smallname =
".mysqli_real_escape_string($this->Connection, $this->Station)."
OR code =
".mysqli_real_escape_string($this->Connection, $this->Station)."
AND land =
NL
LIMIT
1");
return $this->returnData($this->setAssoc($result), $method);
}
public function __destruct() {
$this->Connection->close();
}
}
$info = new Info(, );
$info->setStation("Amsterdam Centraal");
echo $info->convert(); // output ASD
?>
Nee. Iedere class mag maar 1 verantwoordelijkheid hebben. Je doet DB dingen in je info class. Dat klopt niet.
Raaoul schreef:Dus ik moet ipv van regel 23 op regel 62 doen. (Zonder $this)Nee. Iedere class mag maar 1 verantwoordelijkheid hebben. Je doet DB dingen in je info class. Dat klopt niet.
Priveberichten
Afbeelding niet beschikbaarDe bron kon niet worden geladen (i.imgur.com).Bron openen ↗
Afbeelding niet beschikbaarDe bron kon niet worden geladen (i.imgur.com).Bron openen ↗
Profiel pagina
Afbeelding niet beschikbaarDe bron kon niet worden geladen (i.imgur.com).Bron openen ↗
Afbeelding niet beschikbaarDe bron kon niet worden geladen (i.imgur.com).Bron openen ↗
Afbeelding niet beschikbaarDe bron kon niet worden geladen (i.imgur.com).Bron openen ↗Profiel pagina
Afbeelding niet beschikbaarDe bron kon niet worden geladen (i.imgur.com).Bron openen ↗
Shahiem schreef:Wow, dat is wel heel erg nice

Raaoul schreef:Sublime Text +1

