OntoSys  

PHP

Emacs mode for PHP

We wrote a major mode for GNU Emacs, providing automatic formatting and syntax-coloring for the PHP language. We have tested this mode with Emacs 20.4 -- it may require Emacs 20 or later. The code is licensed with the GPL.

Phiki-Wiki, a PHP implementation of Wiki-Wiki

Wiki-Wiki is Ward Cunningham's simple system where an HTTP server allows users to browse and update a network of pages. Updating is done through a simple web interface that allows the author to mark up the page and link to other Wiki pages with a simple syntax -- the author does not (and can not) use any HTML.

Wiki-Wiki was originally written in Perl and has been implemented again in many languages. We have created a PHP3 implementation of Wiki-Wiki, hoping to provide the fastest Wiki server yet since PHP3 can run inside Apache and avoid the CGI fork/exec overhead. Our objective is to match the PyWiki implementation feature for feature, so that PyWiki and PhikiWiki can share the same repository. We did succeed in creating a working implementation, but it's not as fast as we hoped, apparently because of the awkward parsing/substitution algorithm that we used in the absence of "named group" regular expression handling in PHP3.

PHP templates

PHPlib provides a Template class that works very well. We've written up two approaches to using PHPlib template:
  1. Separate PHP and HTML files for each page. This, our currently favored scheme, does not mix PHP and HTML in single source files.
  2. In an older scheme for using whole-page templates, we kept the shared layout in separate HTML files, but implemented page-specific content as a combined PHP/HTML file.

Supporting cacheing of PHP pages

We wrote up a scheme for generating cacheable pages via PHP.

PHP gotcha's

PHP has several language features that can surprise programmers used to other languages.

  1. Variables need an initial '$ in their name every time they appear, not just when accessing their value.
    Right Wrong
    function my_func($x) { ...

    function my_func(x) { ...

    global $x;

    global x;

    var $x; var x;
  2. When calling a constructor without arguments, do not use parentheses.
    Right   Wrong
    $x = new Foo;  

    $x = new Foo();

Saving a variable value

To save a PHP variable such that once set it is available when the document calls itself, make it the value of a hidden form variable:

<input type=hidden name="my_var" value="<?php echo $my_var ?>">

When this document calls itself, any value assigned to my_var is passed to the (same) document as a form variable, rather than having to pass it explicitly in a query string.


OntoSys, Inc. - 38W242 Deerpath Rd - Batavia, IL 60510
phone +1.630.879.1312 - fax +1.630.879.1370
email info@ontosys.com - www.ontosys.com
Last modified: 1970-01-01 00:00 Z.
Copyright © 1999 - 2004 by Fred Yankowski.
All rights reserved.