Object-Oriented Programming with PHP

Posted on June 28, 2009, under Programming

The recent PHP versions now supports object-oriented programming or OOP, which usually are in class form. Since PHP OOP are in class form,  they have accessors, mutators, data members, etc. — much like the usual OOP programming languages. Last week, we started a short crash course with Web Development with PHP/MYSQL. So, I introduced a bit of OOP since most of the participants have the idea already about OOP ( in Java, C++).

Here’s a snippet I used as a demo during our short session:

<?php
class demo {
     var $name;
     function setName($nombre)
     {
          $this->name = $nombre;
     }
     function getName()
     {
          return $this->name;
     }
}
$naming = new demo();
$naming->setName("Jerome Locson");
echo $naming->getName();
?>

I guess if you have a  background in programming, you know how the code works. And if not, just drop me comment and I am willing to answer it.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Ping.fm
  • StumbleUpon
  • Suggest to Techmeme via Twitter
  • Technorati
  • Twitter
Tags: , , , ,