PHP Hello World Class

From Resin 3.0

(Difference between revisions)
Jump to: navigation, search
Line 40: Line 40:
 
  </body>
 
  </body>
 
  </html>
 
  </html>
 +
 +
Now with Quercus, Resin's implementation of PHP, you can define a class in java and incorporate it in your PHP code.  You can use the java class just like you would use the class "Foo" above.
 +
 +
The following article describes the steps necessary to accomplish this.  Furthermore, as you will see, you can take advantage of Resin's built-in ability to compile your java class on the fly.
 +
 +
So if you want to modify the java file, all you have to do is re-save it and resin will do the rest.
 +
 +
Yes... it's that easy.

Revision as of 20:24, 28 December 2005


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>

Now with Quercus, Resin's implementation of PHP, you can define a class in java and incorporate it in your PHP code. You can use the java class just like you would use the class "Foo" above.

The following article describes the steps necessary to accomplish this. Furthermore, as you will see, you can take advantage of Resin's built-in ability to compile your java class on the fly.

So if you want to modify the java file, all you have to do is re-save it and resin will do the rest.

Yes... it's that easy.

Personal tools