PHP Hello World Class

From Resin 3.0

Revision as of 20:21, 28 December 2005 by Creich (Talk | contribs)
Jump to: navigation, search


Introduction

Since PHP 3.0, there has been some support for object-oriented programming. The following sample PHP code shows how to:

  • define a class
  • instantiate that class
  • call methods on the instance of the class

SamplePHPClass.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>

<?php

class Foo {

  var $bar;

  function setBar($value) {
    $this->bar = $value;
  }

  function someFunction($param) {
    echo $param.$this->bar."<br/>";  
  }

}

$foo = new Foo();

$foo->setBar("Charles");
$foo->someFunction("Hello, ");

?>
</body>
</html>
Personal tools