PHP 3.0 SGML HOWTO

Stig Bakken, ssb@guardian.no
$Date: 1998/01/05 10:47:27 $ $Revision: 1.10 $

Contents

1. Tools
1.1. SGML Editor
1.2. Conversion tools
2. Writing SGML documents
2.1. LINUXDOC reference
2.2. PHPDOC startup example
2.3. PHPDOC reference
2.3.1. Document structure
2.3.2. PHPDOC elements
2.3.3 Variable types
3. Connecting stuff
3.1. New PHPDOC files
3.2. Label name conventions
4. Converting from SGML
4.1. HTML
4.2. Plain text
4.3. Other formats...

For now this document describes how to find the tools you need on UNIX. Since I am not a Windows user myself, information about SGML on Windows will show up as soon as it has been gathered. This means that Windows users have to give some feedback.

1. Tools

1.1. SGML Editor

Although it is possible to use a simple text editor such as vi or notepad to write the SGML, it is recommended to use an SGML editor that helps you along and makes sure your document is proper SGML conforming to the used document type definition (DTD).

A pretty good and free SGML editor is Emacs or XEmacs with PSGML. XEmacs is a fancier Emacs with better X support and a pile of Emacs Lisp packages included. Emacs is ported to Windows 95/NT.

URLs:

If you do not use XEmacs you probably have to add this to your ~/.emacs file to make sure Emacs finds the installed files:

 (add-to-list 'load-path
   (expand-file-name "PREFIX/share/emacs/site-lisp/psgml"))

Replace PREFIX with the prefix you used when installing psgml (the default is /usr/local).

Anyway you'll need this in your ~/.emacs to load psgml at startup and make sure psgml is used for all files with .sgml file ending:

 (autoload 'sgml-mode "psgml" "Major mode for editing SGML files." t)

The existing .phpdoc files have "<!-- -*- SGML -*- -->" in their header. When Emacs sees a pattern like "-*- foo -*-" in the first line of a file, it tries to go into foo-mode. So to activate psgml for .phpdoc files you can include the above SGML comment in the first lines of the files you write. Or, you can tell Emacs it should always open .phpdoc files in sgml-mode by putting this in ~/.emacs:

 (add-to-list 'auto-mode-alist '("\\.phpdoc$" . sgml-mode))

For Windows users without NTFS, the .emacs file is called _emacs, and resides in the directory given by the HOME environment variable or C:/.

If you have information about other SGML editors, please send it.

1.2. Conversion tools

SGML-Tools (previously known as "Linuxdoc-SGML") contains almost all the things you is needed to verify and convert PHP's SGML documentation (you need Perl, too). Use version 1.0.2 of SGML-Tools.

URLs:


2. Writing SGML documents

2.1. LINUXDOC reference

2.2. PHPDOC startup example

2.3. PHPDOC reference

2.3.1. Document structure

The structure of PHPDOC can be represented with the following element tree. Each level in the tree represents the possible contents of the tag on the level above.
PHPDOC (1)
FUNCDEF (*)
ARG (*)
text
RETURNS (1?)
text
text
text - any of these elements:
AREF
text except AREF
FREF
text except FREF
FUNC
text except FUNC
VAR
text except VAR
LIT
text except LIT
CLASSREF
text except CLASSREF
CONFREF
text except CONFREF

2.3.2. PHPDOC elements

This is a complete list of all PHPDOC tags with all their attributes and an explaination of their purpose and usage.
PHPDOC
The top-level tag, the start tag must be included, but the end-tag may be omitted. Attributes:
TITLE (required)
A title of this part of the documentation.

FUNCDEF
Documents a PHP function. Attributes:
NAME (required)
The function name.
CAT (required)
What category of functions and classes this function belongs to.
A list of valid categories may be added later.
RET (required)
What type this function returns. See phpdoc types for possible values.
FIRSTIN (optional)
Which PHP version this function first appeared in.

ARG
Function argument/parameter. Attributes:
NAME (required)
The parameter name (only for documentation reference).
OPTIONAL (optional) defaults to MANDAT
Can be empty (<ARG OPTIONAL ...>) or have the value MANDAT or OPTIONAL. MANDAT means that this argument is mandatory--it must be supplied.
TYPE (required)
The type of this argument. See phpdoc types for possible values.
FIRSTIN (optional)
Which PHP version this argument was introduced in (if it was introduced later than the function was.)

RETURNS
Describes what a function returns. No attributes.

AREF
Refers to an argument in the current FUNCDEF or METHOD. Attributes:
NAME (required)
Name of the attribute given in the ARG tag.

FREF
Refers to a function. Attributes:
NAME (required)
Name of the function referred to.

2.3.3 Variable types

Several of PHPDOC's attributes take a PHP type as a parameter. The permitted PHP type identifiers are:
Type Description
int PHP's integer type
float PHP's float type
string PHP's string type
array a numbered array of any PHP types
assoc an associative array of any PHP types
object an object
mixed any PHP type
varargs variable number of arguments, type not specified
void nothing

3. Connecting stuff

3.1. New PHPDOC files

The main file for the documentation is manual.sgml. This file uses entities (can be compared to a combination of #define and #include in C) to include text from other files. The entities that include the PHPDOC files are defined in the preamble of manual.sgml, which is the section between the "[" character on the first (DOCTYPE) line and "]>".

Steps involved in connecting a new PHPDOC file:

  1. Let us say you have written functions/ldap.phpdoc. You should then add this to the preamble:
    <!entity ldapref system "functions/ldap.sgml">
    
    This tells the SGML parser that when "ldapref" is referenced it should read the file functions/ldap.sgml.

    Note that the file name extension used here is not .phpdoc, but .sgml. The Makefile handles the conversion.

  2. Refer to the ldapref entity where you want to include it. Keep in mind that PHPDOC documents are converted into LINUXDOC sections. Internal functions should be added to the "internal functions" chapter in chapters/functions.sgml. Add something like this (the bold part is what to add):
    <chapt>Internal functions
     ...
     &ldapref;
     ...
    
  3. Then, to make sure the .phpdoc file is converted to .sgml, you have to tell make about it. Add the .sgml file to the FUNCREF variable in Makefile.in. Example (the bold text is the change):
    FUNCREF=functions/oracle.sgml \
            functions/ldap.sgml \
    	functions/math.sgml \
    	functions/mysql.sgml \
    	functions/pgsql.sgml \
    	functions/strings.sgml \
    	functions/adabas.sgml
    
  4. Finally, regenerate Makefile:
    (cd .. ; ./config.status)
    

3.2. Label name conventions

When making or refering to labels in the LINUXDOC files, there are some conventions that should kept:

4. Converting from SGML

4.1. HTML

You convert all the SGML files to HTML by running "make html". The current Makefile setup splits the chapters and appendices into separate files. The main file is called manual.html, and the other files are manual-n.html.

If sgml2html shows some error messages like this:

  sgml2html -l -2 manual.sgml
  Making manual.html from manual.sgml.
  Problem with @@ref(id = security)!
  Problem with @@ref(id = func:include)!
  Problem with @@ref(id = func:pg_pconnect)!
  Problem with @@ref(id = func:stripslashes)!
..it is because of references that point to labels that do not exist. See label name conventions.

4.2. Plain text

You convert all the SGML files to plain text by running "make text". The results can be seen in manual.txt.

Note: there seems to be a bug in the 0.99.0 sgml2txt filter that messes up the section numbering in the table of contents.

4.3 Other formats...

SGML-Tools supports converting SGML to info, LaTeX, lyx and rtf as well. PHP's documentation should be convertable to any of these formats in theory, but I have not tested it good enough to document it here yet.


Send feedback and questions to ssb@guardian.no