PHP hello world module (jar version)

From Resin 3.0

(Difference between revisions)
Jump to: navigation, search
Line 9: Line 9:
 
===HelloWorldSampleClass.java===
 
===HelloWorldSampleClass.java===
 
  package Example;<br/>
 
  package Example;<br/>
 
 
  import com.caucho.php.module.AbstractPhpModule;
 
  import com.caucho.php.module.AbstractPhpModule;
 
  import com.caucho.php.env.StringValue;<br/>
 
  import com.caucho.php.env.StringValue;<br/>
 
 
  public class HelloWorldSampleClass extends AbstractPhpModule {<br/>
 
  public class HelloWorldSampleClass extends AbstractPhpModule {<br/>
 
 
   public StringValue say_hello(String name)
 
   public StringValue say_hello(String name)
 
   {
 
   {

Revision as of 19:20, 2 December 2005


Contents

Introduction

This short article is intended for java programers who are interested in creating there own libraries which can be invoked from within a PHP page. It assumes that Resin's PHP implementation is installed and working correctly on your computer. Please see the related article PHP Hello World for more information on installing Resin for the first time.

Step 1: Create HelloWorldSampleClass.java

HelloWorldSampleClass.java

package Example;
import com.caucho.php.module.AbstractPhpModule; import com.caucho.php.env.StringValue;
public class HelloWorldSampleClass extends AbstractPhpModule {
public StringValue say_hello(String name) { return new StringValue("Hello, " + name); } }

Step 2: Create com.caucho.php.PhpModule

Example.HelloWorldSampleClass

Step 3: Create example.jar

Step 4: Create a PHP page

javahello.php

<?php
$name = say_hello("Charles");
echo $name;
?>


Conclusion

Personal tools