DEV Community

Discussion on: Juniors Literally Can't Write Switch Statements: What Senior PHP Developers Need to Focus On

Collapse
 
vasilvestre profile image
Valentin Silvestre

I'm sad because it's true.
I'm a Junior and I don't even know what a Dependence Injection really is.
I've learn PHP with Symfony ; I can make clean and pro code in Symfony.

But I don't know a lot of things about vanilla PHP..
In one hand, company ask us to code with FW and in other hand we want to learn basic code..

Collapse
 
robdwaller profile image
Rob Waller

Think of a small app you could build and then don't use any frameworks, write your own code for everything. That's a good way to learn. Forces you to think threw some of the issues that framework builders also think through.

Collapse
 
vasilvestre profile image
Valentin Silvestre

But in fact, I'm trying to don't use switch function.. In most of case, if/else are cleaner.

Instead of this :

<?php

switch (true) {
    case $this->object instanceof SomeClass:
        //Do Something
    break;
    //etc, etc...

I prefer ternary operator or simple if :

<?php

if ($this->object instanceOf SomeClass) {
   // Do something
}

return $this->object instanceOf SomeClass ? 'foo' : 'bar';

And I'm triggered that there's no default in your switch !