Im trying to find best practices to write PHP.
I just wonder is this a bad habit.
For example, processing variables.
$var = 1
$var = doSomething($var);
$var = doSomething2($var);
$var = doSomething3($var);
It looks a bit awful.
Here is a example of a real code that I just did:
$this->rSum = explode(",", $this->options["rSum"]);
$this->rSum = array_combine(array_values($this->rSum), array_fill(0, count($this->rSum), 0));
If someone could pass me some good tutorials of writing cleaner code generally it would be nice!
Its me again asking stupid questions. :)
By the way..
How much automatic processing can there be in models?
I have a model that has a execute method and when I call it, it does a lot of things like reading a definition file and making database queries.
For example
$object = new Object()
$object->setFile("example.txt");
$object->execute();
// Then i can fetch things from it
echo $object->getName();
Smart code is not necessarily good code in my opinion. I'd personally prefer clean, simple and easy to understand code. Your 2 liner will make your peer think hard, as opposed to your init "bad" code.
That's just my take anyway
The most important, be consistent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With