Het Wat heb jij vandaag geprogrammeerd? topic

Gestart doorAarclay4.538 reacties23.755 weergaven

4.539 berichten · pagina 143 van 303

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Sevvlor schreef:
Afbeelding

Helemaal werkend gemaakt biggrin
Nice!
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
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!
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Lees de tutorial over OOP nog eens door op phptuts.nl en houd je aan de php standaarden.
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Dylanh schreef:
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!

CLASSEN != OOP nopompom
Wanneer leren mensen dit nou eens.
0
Berichten
1.533
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Rik schreef:
Eerdere citaten tonen
Dylanh schreef:
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!

CLASSEN != OOP nopompom
Wanneer leren mensen dit nou eens.

PHP.net zegt dat clases wel OOP zijn.
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Poedeltje schreef:
Eerdere citaten tonen
Rik schreef:
Eerdere citaten tonen
Dylanh schreef:
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!

CLASSEN != OOP nopompom
Wanneer leren mensen dit nou eens.

PHP.net zegt dat clases wel OOP zijn.

Link?

OOP = classen
classen != OOP
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Oop zijntoch objecten? $Mysqli->query(); etc?
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dylanh schreef:
Oop zijntoch objecten? $Mysqli->query(); etc?
OOP = Object-oriented programming

Volg eens wat tutorials naar OOP dan zie je de logica er na een tijd wel van in.
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Poedeltje schreef:
Eerdere citaten tonen
Rik schreef:
Eerdere citaten tonen
Dylanh schreef:
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!

CLASSEN != OOP nopompom
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 zijntoch objecten? $Mysqli->query(); etc?
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.
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
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
?>
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Nee. Iedere class mag maar 1 verantwoordelijkheid hebben. Je doet DB dingen in je info class. Dat klopt niet.
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Raaoul schreef:
Nee. Iedere class mag maar 1 verantwoordelijkheid hebben. Je doet DB dingen in je info class. Dat klopt niet.
Dus ik moet ipv van regel 23 op regel 62 doen. (Zonder $this)
0
Berichten
20.364
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Priveberichten
Afbeelding
Afbeelding

Profiel pagina
Afbeelding
smile
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Shahiem schreef:
Priveberichten

Afbeelding
Afbeelding

Profiel pagina
Afbeelding
smile
Wow, dat is wel heel erg nice kwijl
0
Berichten
3.874
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Raaoul schreef:
Net wat geprutst met Python, geniale taal yummie
Afbeelding
Sublime Text +1
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren