Upgrade to Pro — share decks privately, control downloads, hide ads and more …

UpstatePHP 101: Object Mayhem

UpstatePHP 101: Object Mayhem

Avatar for Andrew Lechowicz

Andrew Lechowicz

May 19, 2016

Other Decks in Programming

Transcript

  1. Programming Languages are Tools • PHP • Erlang • C/C++

    • Java • JavaScript • Chicken • Ruby
  2. Not Every Language has Every Feature • PHP had some

    basic OOP features in 4.0 • 5.0 has a full object model
  3. Classes • Classes -> Blueprints • Contain all the informa5on

    needed to build a house • Can't live in a blueprint
  4. A Basic Class class ClassName { } • Begin with

    class • Followed by the name of the class ClassName • Curly braces surround the defini:on {...}
  5. Proper&es & Methods class ClassName { public $var = 'a

    default value'; // method declaration public function displayVar() { echo $this->var; } } • Constants -> Constants • Variables -> Proper3es • Func3ons -> Methods
  6. New Objects! <?php $instance = new SimpleClass(); // This can

    also be done with a variable: $className = 'SimpleClass'; $instance = new $className(); // new SimpleClass()