Adventures in PHP
LAF (“Life after Flatiron”) has been a mixture of emotions, but has primarily meant that I’m exploring new technologies, languages and stacks. I’m currently learning PHP, among other things, for my LAF job. I’m finding that PHP isn’t very different from Ruby; they’re both scripting languages, so logically very similar. Problems I’m familiar with in Ruby can be easily solved in PHP, just with a different syntax.
I happily breezed through Codecademy’s PHP Track, at a pace that made me feel quite pleased with myself. :) Three months ago, the Ruby Track took more than twice as long to go through.
Once I became familiar with the basic syntax of PHP, I decided to expand my learning by writing some simple programs that I had previously done in Ruby.
First, naturally, was FizzBuzz, written procedurally. For my own clarity and practice, I pushed the fizzes, buzzes, and fizzbuzzes into an array:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Next, practicing switch statements (like case statements in Ruby), I wrote a vowel checker program. I included some syntactic sugar with the endswitch;
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
As a fan of object orientation (being an organizational freak, I guess it makes sense that I would love classes), I created a Triangle class which will return the type of triangle, given the sides. Additionally, I tried my hand at some Exception throwing, which throws an error if the sides do not make a valid triangle. Exceptions, like in Ruby, are classes that your custom class can inherit from.
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 |
|