Hallo,
Wat is jullie "criterium" om iets als class-property in te stellen?
Stel je hebt in class foobar de variabele $x nodig. Deze variabele bevat best veel data. Nu heb ik een situatie waarbij ik dit had gedaan.
<?php
class Foo {
private $x;
public function __construct($x) {
$this->x = $x;
}
public function doeIets() {
$foobar = new Foobar($this->x);
$foobar->doeIets();
}
}
class Foobar {
private $x;
public function __construct($x) {
$this->x = $x;
}
public function doeIets() {
$x = $this->x;
// doe iets met $x
}
}
$x = array($heleboel_data);
$foo = new Foo($x);
$foo->doeIets();
?>
Zoals je kunt zien sla ik $x nu in 2 classes op als class-property.
En nu vraag ik me af, kan ik niet beter dit doen:
<?php
class Foo {
public function doeIets($x) {
$foobar = new Foobar();
$foobar->doeIets($x);
}
}
class Foobar {
public function doeIets($x) {
// doe iets met $x
}
}
$x = array($heleboel_data);
$foo = new Foo();
$foo->doeIets($x);
?>
Wat vinden jullie?
869 views