cvs: pearweb /public_html/manual class.pear-error.php class.pear.php copyright.php getting-started.php index.php introduction.php packages.auth.php
packages.net_checkip.php packages.php packages.skeleton.php preface.php reference.php standards.comments.php standards.control.php standards.cvs.php
standards.exampleurls.php standards.funcalls.php standards.funcdef.php standards.header.php standards.including.php standards.naming.php standards.php
standards.tags.php
| From: | Martin Jansen | Date: | Sun, 14 Oct 2001 15:27:54 +0000 |
| Subject: | cvs: pearweb /public_html/manual class.pear-error.php class.pear.php copyright.php getting-started.php index.php introduction.php packages.auth.php packages.net_checkip.php packages.php packages.skeleton.php preface.php reference.php standards.comments.php standards.control.php standards.cvs.php standards.exampleurls.php standards.funcalls.php standards.funcdef.php standards.header.php standards.including.php standards.naming.php standards.php standards.tags.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-1011@lists.php.net to get a copy of this message | ||
mj Sun Oct 14 11:27:54 2001 EDT
Added files:
/pearweb/public_html/manual class.pear-error.php class.pear.php
copyright.php getting-started.php
index.php introduction.php
packages.auth.php
packages.net_checkip.php packages.php
packages.skeleton.php preface.php
reference.php standards.comments.php
standards.control.php standards.cvs.php
standards.exampleurls.php
standards.funcalls.php
standards.funcdef.php
standards.header.php
standards.including.php
standards.naming.php standards.php
standards.tags.php
Log:
* first version of the PEAR manual
# More information soon on pear-dev
Index: pearweb/public_html/manual/class.pear-error.php +++ pearweb/public_html/manual/class.pear-error.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('class.pear.php', 'PEAR'), 'next' => array('packages.php', 'PEAR Packages'), 'up' => array('reference.php', 'PEAR'), 'toc' => array( array('reference.php#reference', ''), array('reference.php#AEN200', ''), array('reference.php#AEN201', ''), array('class.pear.php', 'PEAR'), array('class.pear-error.php', 'PEAR_Error')))); manualHeader('PEAR_Error','class.pear-error.php'); ?><H1 ><A NAME="class.pear-error" >PEAR_Error</A ></H1 ><DIV CLASS="refnamediv" ><A NAME="AEN338" ></A >PEAR_Error -- PEAR error mechanism base class</DIV ><DIV CLASS="refsynopsisdiv" ><A NAME="AEN341" ></A ><H2 >Synopsis</H2 ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="synopsis" >$err = new PEAR_Error($msg);</PRE ></TD ></TR ></TABLE ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN344" ></A ><H2 >Error Modes</H2 ><P > An error object has a mode of operation that can be set with one of the following constants: <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="constant.pear-error-return" >PEAR_ERROR_RETURN</A ></DT ><DD ><P > Just return the object, don't do anything special in PEAR_Error's constructor. </P ></DD ><DT ><A NAME="constant.pear-error-print" >PEAR_ERROR_PRINT</A ></DT ><DD ><P > Print the error message in the constructor. The execution is not interrupted. </P ></DD ><DT ><A NAME="constant.pear-error-trigger" >PEAR_ERROR_TRIGGER</A ></DT ><DD ><P > Use PHP's <B CLASS="function" >trigger_error()</B > function to raise an internal error in PHP. The execution is aborted if you have defined your own PHP error handler or if you set the error severity to E_USER_ERROR. </P ></DD ><DT ><A NAME="constant.pear-error-die" >PEAR_ERROR_DIE</A ></DT ><DD ><P > Print the error message and exit. Execution is of course aborted. </P ></DD ><DT ><A NAME="constant.pear-error-callback" >PEAR_ERROR_CALLBACK</A ></DT ><DD ><P > Use a callback function or method to handle errors. Execution is aborted. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN369" ></A ><H2 >Properties</H2 ><P ></P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN372" ></A ><H2 >Methods</H2 ><DIV CLASS="funcsynopsis" ><A NAME="AEN374" ></A ><P ></P ><P ><CODE ><CODE CLASS="FUNCDEF" ><B CLASS="function" >PEAR_Error::PEAR_Error</B ></CODE > ([message code mode options userinfo]]]]])</CODE ></P ><P ></P ></DIV ><DIV CLASS="refsect2" ><A NAME="AEN389" ></A ><H3 >Description</H3 ><P > PEAR_Error constructor. Parameters: <P ></P ><DIV CLASS="variablelist" ><DL ><DT >message</DT ><DD ><P > error message, defaults to "unknown error" </P ></DD ><DT >code</DT ><DD ><P > error code (optional) </P ></DD ><DT >mode</DT ><DD ><P > Mode of operation. See the <A HREF="class.pear-error.php#error-modes" >error modes</A > section for details. </P ></DD ><DT >options</DT ><DD ><P > If the mode of can have any options specified, use this parameter. Currently the "trigger" and "callback" modes are the only using the options parameter. For trigger mode, this parameter is one of <TT CLASS="constant" ><B >E_USER_NOTICE</B ></TT >, <TT CLASS="constant" ><B >E_USER_WARNING</B ></TT > or <TT CLASS="constant" ><B >E_USER_ERROR</B ></TT >. For callback mode, this parameter should contain either the callback function name (string), or a two-element (object, string) array representing an object and a method name. </P ></DD ></DL ></DIV > </P ></DIV ></DIV ><?php manualFooter('PEAR_Error','class.pear-error.php'); ?> Index: pearweb/public_html/manual/class.pear.php +++ pearweb/public_html/manual/class.pear.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('reference.php', 'PEAR'), 'next' => array('class.pear-error.php', 'PEAR_Error'), 'up' => array('reference.php', 'PEAR'), 'toc' => array( array('reference.php#reference', ''), array('reference.php#AEN200', ''), array('reference.php#AEN201', ''), array('class.pear.php', 'PEAR'), array('class.pear-error.php', 'PEAR_Error')))); manualHeader('PEAR','class.pear.php'); ?><H1 ><A NAME="class.pear" >PEAR</A ></H1 ><DIV CLASS="refnamediv" ><A NAME="AEN205" ></A >PEAR -- PEAR base class</DIV ><DIV CLASS="refsynopsisdiv" ><A NAME="AEN208" ></A ><H2 >Synopsis</H2 ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="synopsis" >require_once "PEAR.php";</PRE ></TD ></TR ></TABLE ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="synopsis" >class <TT CLASS="replaceable" ><I >classname</I ></TT > extends PEAR { ... }</PRE ></TD ></TR ></TABLE ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN213" ></A ><H2 >Description</H2 ><P > The PEAR base class provides standard functionality that is used by most PEAR classes. Normally you never make an instance of the PEAR class directly, you use it by subclassing it. </P ><P > Its key features are: <P ></P ><UL ><LI ><P >request-shutdown object "destructors"</P ></LI ><LI ><P >error handling</P ></LI ></UL > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="destructors" ></A ><H2 >PEAR "destructors"</H2 ><P > If you inherit <A HREF="class.pear.php" ><B CLASS="classname" >PEAR</B ></A > in a class called <TT CLASS="replaceable" ><I >ClassName</I ></TT >, you can define a method in it called called _<TT CLASS="replaceable" ><I >ClassName</I ></TT > (the class name with an underscore prepended) that will be invoked when the request is over. This is not a destructor in the sense that you can "delete" an object and have the destructor called, but in the sense that PHP gives you a callback in the object when PHP is done executing. See <A HREF="class.pear.php#example.destructors" >the example</A > below. </P ><P > <DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B ><A NAME="destructors.warning" ></A >Important!</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > In order for destructors to work properly, you must instantiate your class with the "=& new" operator like this: <TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > $obj =& new MyClass(); </PRE ></TD ></TR ></TABLE > </P ><P > If you only use "= new", the object registered in PEAR's shutdown list will be a copy of the object at the time the constructor is called, and it will this copy's "destructor" that will be called upon request shutdown. </P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="error-handling" ></A ><H2 >PEAR Error Handling</H2 ><P > PEAR's base class also provides a way of passing around more complex errors than a true/false value or a numeric code. A PEAR error is an object that is either an instance of the class <A HREF="class.pear-error.php" ><B CLASS="classname" >PEAR_Error</B ></A >, or some class inheriting <A HREF="class.pear-error.php" ><B CLASS="classname" >PEAR_Error</B ></A >. </P ><P > One of the design criteria of PEAR's errors is that it should not force a particular type of output on the user, it should be possible to handle errors without any output at all if that is desirable. This makes it possible to handle errors gracefully, also when your output format is different from HTML (for example WML or some other XML format). </P ><P > The error object can be configured to do a number of things when it is created, such as printing an error message, printing the message and exiting, raising an error with PHP's <B CLASS="function" >trigger_error()</B > function, invoke a callback, or none of the above. This is typically specified in <A HREF="class.pear-error.php" ><B CLASS="classname" >PEAR_Error</B ></A >'s constructor, but all of the parameters are optional, and you can set up defaults for errors generated from each object based on the <A HREF="class.pear.php" ><B CLASS="classname" >PEAR</B ></A > class. See the <A HREF="class.pear.php#example.error1" >PEAR error examples</A > for how to use it and the <A HREF="class.pear-error.php" ><B CLASS="classname" >PEAR_Error</B ></A > reference for the full details. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN247" ></A ><H2 >Examples</H2 ><P > The example below shows how to use the PEAR's "poor man's kinda emulated destructors" to implement a simple class that holds the contents of a file, lets you append data to the object and flushes the data back to the file at the end of the request: <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="example.destructors" ></A ><P ><B >Example 1. PEAR: emulated destructors</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > require_once "PEAR.php"; class FileContainer extends PEAR { var $file = ''; var $contents = ''; var $modified = 0; function FileContainer($file) { $this->PEAR(); // this calls the parent class constructor $fp = fopen($file, "r"); if (!is_resource($fp)) { return; } while (!empty($data = fread($fp, 2048))) { $this->contents .= $data; } fclose($fp); } function append($str) { $this->contents .= $str; $this->modified++; } // The "destructor" is named like the constructor // but with an underscore in front. function _FileContainer() { if ($this->modified) { $fp = fopen($this->file, "w"); if (!is_resource($fp)) { return; } fwrite($fp, $this->contents); fclose($fp); } } } $fileobj =& new FileContainer("testfile"); $fileobj->append("this ends up at the end of the file\n"); // When the request is done and PHP shuts down, $fileobj's // "destructor" is called and updates the file on disk. </PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > PEAR "destructors" use PHP's shutdown callbacks (<B CLASS="function" >register_shutdown_function()</B >), and you can't output anything from these when PHP is running in a web server. So anything printed in a "destructor" gets lost except when PHP is used in command-line mode. Bummer. </P ><P > Also, see the <A HREF="class.pear.php#destructors.warning" >warning</A > about how to instantiate objects if you want to use the destructor. </P ></BLOCKQUOTE ></DIV > </P ><P > The next examples illustrate different ways of using PEAR's error handling mechanism. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="example.error1" ></A ><P ><B >Example 2. PEAR error example (1)</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > function mysockopen($host = "localhost", $port = 8090) { $fp = fsockopen($host, $port, $errno, $errstr); if (!is_resource($fp)) { return new PEAR_Error($errstr, $errno); } return $fp; } $sock = mysockopen(); if (PEAR::isError($sock)) { print "mysockopen error: ".$sock->getMessage()."<BR>\n" } </PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > This example shows a wrapper to <B CLASS="function" >fsockopen()</B > that delivers the error code and message (if any) returned by fsockopen in a PEAR error object. Notice that <B CLASS="function" >PEAR::isError()</B > is used to detect whether a value is a PEAR error. </P ><P > PEAR_Error's mode of operation in this example is simply returning the error object and leaving the rest to the user (programmer). This is the default error mode. </P ><P > In the next example we're showing how to use default error modes: </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="example.error2" ></A ><P ><B >Example 3. PEAR error example (2)</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > class TCP_Socket extends PEAR { var $sock; function TCP_Socket() { $this->PEAR(); } function connect($host, $port) { $sock = fsockopen($host, $port, $errno, $errstr); if (!is_resource($sock)) { return $this->raiseError($errstr, $errno); } } } $sock = new TCP_Socket; $sock->setErrorHandling(PEAR_ERROR_DIE); $sock->connect("localhost", 8090); print "still alive<BR>\n"; </PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > Here, we set the default error mode to <A HREF="class.pear-error.php#constant.pear-error-die" ><TT CLASS="constant" ><B >PEAR_ERROR_DIE</B ></TT ></A >, and since we don't specify any error mode in the raiseError call (that'd be the third parameter), raiseError uses the default error mode and exits if fsockopen fails. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN274" ></A ><H2 >Global Variables Used</H2 ><P > The PEAR class uses some global variables to register global defaults, and an object list used by the "destructors". All of the global variables associated with the PEAR class have a <TT CLASS="literal" >_PEAR_</TT > name prefix. </P ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT >$_PEAR_default_error_mode</DT ><DD ><P > If no default error mode is set in an object, this mode will be used. Must be one of <A HREF="class.pear-error.php#constant.pear-error-return" ><TT CLASS="constant" ><B >PEAR_ERROR_RETURN</B ></TT ></A >, <A HREF="class.pear-error.php#constant.pear-error-print" ><TT CLASS="constant" ><B >PEAR_ERROR_PRINT</B ></TT ></A >, <A HREF="class.pear-error.php#constant.pear-error-trigger" ><TT CLASS="constant" ><B >PEAR_ERROR_TRIGGER</B ></TT ></A >, <A HREF="class.pear-error.php#constant.pear-error-die" ><TT CLASS="constant" ><B >PEAR_ERROR_DIE</B ></TT ></A > or <A HREF="class.pear-error.php#constant.pear-error-callback" ><TT CLASS="constant" ><B >PEAR_ERROR_CALLBACK</B ></TT ></A >. </P ><P > Don't set this variable directly, call <B CLASS="function" >PEAR::setErrorHandling()</B > as a static method like this: <DIV CLASS="informalexample" ><A NAME="AEN291" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > PEAR::setErrorHandling(PEAR_ERROR_DIE); </PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DD ><DT >$_PEAR_default_error_options</DT ><DD ><P > If the error mode is <A HREF="class.pear-error.php#constant.pear-error-trigger" ><TT CLASS="constant" ><B >PEAR_ERROR_TRIGGER</B ></TT ></A >, this is the error level (one of <TT CLASS="constant" ><B >E_USER_NOTICE</B ></TT >, <TT CLASS="constant" ><B >E_USER_WARNING</B ></TT > or <TT CLASS="constant" ><B >E_USER_ERROR</B ></TT >). </P ><P > Don't set this variable directly, call <B CLASS="function" >PEAR::setErrorHandling()</B > as a static method like this: <DIV CLASS="informalexample" ><A NAME="AEN303" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > PEAR::setErrorHandling(PEAR_ERROR_TRIGGER, E_USER_ERROR); </PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DD ><DT >$_PEAR_default_error_callback</DT ><DD ><P > If no <TT CLASS="replaceable" ><I >options</I ></TT > parameter is used when an error is raised and the error mode is <A HREF="class.pear-error.php#constant.pear-error-callback" ><TT CLASS="constant" ><B >PEAR_ERROR_CALLBACK</B ></TT ></A >, the value of this variable is used as the callback. This means that you can switch the error mode temporarily and return to callback mode without specifying the callback function again. A string value represents a function, a two-element array with an object at index 0 and a string at index 1 represents a method. </P ><P > Again, don't set this variable directly, call <B CLASS="function" >PEAR::setErrorHandling()</B > as a static method like this: <DIV CLASS="informalexample" ><A NAME="AEN313" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, "my_error_handler"); </PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P > Here is an example of how you can switch back and forth without specifying the callback function again: <DIV CLASS="informalexample" ><A NAME="AEN316" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > PEAR::setErrorMode(PEAR_ERROR_CALLBACK, "my_function_handler"); do_some_stuff(); PEAR::setErrorMode(PEAR_ERROR_DIE); do_some_critical_stuff(); PEAR::setErrorMode(PEAR_ERROR_CALLBACK); // now we're back to using my_function_handler again </PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN318" ></A ><H2 >Methods</H2 ><DIV CLASS="refsect2" ><A NAME="function.pear" ></A ><H3 >PEAR::PEAR</H3 ><DIV CLASS="funcsynopsis" ><A NAME="AEN322" ></A ><P ></P ><P ><CODE ><CODE CLASS="FUNCDEF" >PEAR()</CODE > (void)</CODE ></P ><P ></P ></DIV ><P > This is the PEAR class constructor. Call it from the constructor of every class inheriting the PEAR class. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN327" ></A ><P ><B >Example 4. PEAR Class Constructor Example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > class MyClass extends PEAR { var $foo, $bar; function MyClass($foo, $bar) { $this->PEAR(); $this->foo = $foo; $this->bar = $bar; } } </PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="refsect2" ><A NAME="function.-pear" ></A ><H3 >PEAR::_PEAR</H3 ><DIV CLASS="funcsynopsis" ><A NAME="AEN332" ></A ><P ></P ><P ><CODE ><CODE CLASS="FUNCDEF" >_PEAR()</CODE > (void)</CODE ></P ><P ></P ></DIV ><P > This is the PEAR class destructor. It is called during request shutdown. </P ></DIV ></DIV ><?php manualFooter('PEAR','class.pear.php'); ?> Index: pearweb/public_html/manual/copyright.php +++ pearweb/public_html/manual/copyright.php <HTML ><HEAD ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.60"><LINK REL="HOME" TITLE="PEAR Manual" HREF="index.php"><LINK REL="NEXT" TITLE="Preface" HREF="preface.php"></HEAD ><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PEAR Manual</TH ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="legalnotice" ><A NAME="copyright" ></A ><P ><B >Copyright</B ></P ><P > This manual is © Copyright 2001 by the PHP PEAR Group. The members of this group are listed on the front page of this manual. </P ><P > This manual can be redistributed under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" > </TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.php" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" > </TD ></TR ></TABLE ></DIV ></BODY ></HTML > Index: pearweb/public_html/manual/getting-started.php +++ pearweb/public_html/manual/getting-started.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('preface.php', 'Preface'), 'next' => array('introduction.php', 'Introduction'), 'up' => array('index.php', 'PEAR Manual'), 'toc' => array( array('index.php#manual', ''), array('index.php#AEN0', ''), array('index.php#bookinfo', ''), array('index.php#AEN0', ''), array('preface.php', 'Preface'), array('getting-started.php', 'Getting Started'), array('packages.php', 'PEAR Packages')))); manualHeader('Getting Started','getting-started.php'); ?><DIV CLASS="PART" ><A NAME="getting-started" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >I. Getting Started</H1 ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT >1. <A HREF="introduction.php" >Introduction</A ></DT ><DT >2. <A HREF="standards.php" >Coding Standards</A ></DT ><DT >I. <A HREF="reference.php" >PEAR Reference Manual</A ></DT ></DL ></DIV ></DIV ></DIV ><?php manualFooter('Getting Started','getting-started.php'); ?> Index: pearweb/public_html/manual/index.php +++ pearweb/public_html/manual/index.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('index.php#AEN0', ''), 'next' => array('preface.php', 'Preface'), 'up' => array('index.php#AEN0', ''), 'toc' => array( array('index.php#AEN0', '')))); manualHeader('PEAR Manual','index.php'); ?><DIV CLASS="BOOK" ><A NAME="manual" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" ><A NAME="manual" >PEAR Manual</A ></H1 ><DIV CLASS="author" >Martin Jansen</DIV ><H4 CLASS="EDITEDBY" >Edited by</H4 ><H3 CLASS="editor" >Martin Jansen</H3 ><P CLASS="copyright" ><A HREF="copyright.php" >Copyright</A > © 2001 by the PHP PEAR Group</P ><HR></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="preface.php" >Preface</A ></DT ><DD ><DL ><DT ><A HREF="preface.php#about" >About this Manual</A ></DT ></DL ></DD ><DT >I. <A HREF="getting-started.php" >Getting Started</A ></DT ><DD ><DL ><DT >1. <A HREF="introduction.php" >Introduction</A ></DT ><DT >2. <A HREF="standards.php" >Coding Standards</A ></DT ><DT >I. <A HREF="reference.php" >PEAR Reference Manual</A ></DT ></DL ></DD ><DT >II. <A HREF="packages.php" >PEAR Packages</A ></DT ><DD ><DL ><DT ><A HREF="packages.skeleton.php" >Skeleton for creating PEAR docbook documentation</A ></DT ><DT ><A HREF="packages.auth.php" >Auth: creating authentication realms</A ></DT ><DT ><A HREF="packages.net_checkip.php" >Net_CheckIP: Validation of IPv4 adresses</A ></DT ></DL ></DD ></DL ></DIV ></DIV ><?php manualFooter('PEAR Manual','index.php'); ?> Index: pearweb/public_html/manual/introduction.php +++ pearweb/public_html/manual/introduction.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('getting-started.php', 'Getting Started'), 'next' => array('standards.php', 'Coding Standards'), 'up' => array('getting-started.php', 'Getting Started'), 'toc' => array( array('getting-started.php#getting-started', ''), array('getting-started.php#AEN0', ''), array('introduction.php', 'Introduction'), array('getting-started.php#AEN0', ''), array('standards.php', 'Coding Standards'), array('getting-started.php#AEN0', ''), array('reference.php', 'PEAR')))); manualHeader('Introduction','introduction.php'); ?><DIV CLASS="chapter" ><H1 ><A NAME="introduction" >Chapter 1. Introduction</A ></H1 ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="introduction.php#pear-whatis" >What is PEAR?</A ></DT ></DL ></DIV ><P > PEAR is dedicated to Malin Bakken, born 1999-11-21 (the first PEAR code was written just two hours before she was born). </P ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="pear-whatis" >What is PEAR?</A ></H1 ><P > PEAR is a code repository for PHP extensions and PHP library code inspired by TeX's CTAN and Perl's CPAN. </P ><P > The purpose of PEAR is: <P ></P ><UL ><LI ><P > to provide a consistent means for library code authors to share their code with other developers </P ></LI ><LI ><P > to give the PHP community an infrastructure for sharing code </P ></LI ><LI ><P > to define standards that help developers write portable and reusable code </P ></LI ><LI ><P > to provide tools for code maintenance and distribution </P ></LI ></UL > </P ></DIV ></DIV ><?php manualFooter('Introduction','introduction.php'); ?> Index: pearweb/public_html/manual/packages.auth.php +++ pearweb/public_html/manual/packages.auth.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('packages.skeleton.php', ''), 'next' => array('packages.net_checkip.php', ''), 'up' => array('packages.php', 'PEAR Packages'), 'toc' => array( array('packages.php#packages', ''), array('packages.php#AEN0', ''), array('packages.skeleton.php', ''), array('packages.php#AEN0', ''), array('packages.auth.php', ''), array('packages.php#AEN0', ''), array('packages.net_checkip.php', '')))); manualHeader('','packages.auth.php'); ?><DIV CLASS="ARTICLE" ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" ><A NAME="AEN435" >Auth: creating authentication realms</A ></H1 ><HR></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="packages.auth.auth" >Auth</A ></H1 ><P >The PEAR Auth package helps you to create PHP based authentication systems.</P ><P >The biggest advantage of PEAR Auth is the fact, that it uses storage containers to read/write the login data. This containers can be easily docked into the auth system and can theoretically access to databases, files, LDAP servers etc. </P ><P >Usage example:</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > require_once "Auth/Auth.php"; $auth = new Auth("DB", "mysql://martin:test@localhost/test"); $auth->start(); if ($auth->getAuth()) { echo "You are successfully logged in. Welcome to the system.\n"; echo "This text is only visible for you because you are logged in.\n"; } </PRE ></TD ></TR ></TABLE ><P > The function <B CLASS="function" >Auth()</B > is the constructor of the Auth class. You can pass two parameters towards it: The first parameter <TT CLASS="parameter" ><I >$storageDriver</I ></TT > represents the type of storage container, the class shall use. In our example, the container is a database. The second parameter <TT CLASS="parameter" ><I > $storageOptions</I ></TT > defines some parameters that are passed to the storage container. When using the PEAR DB layer, this 2nd parameter has to be the DSN string that tells the DB layer how to connect. </P ><P > The function <B CLASS="function" >start()</B > checks, if the user is already logged in. If this check leads into a positive result, the function does nothing more. If <B CLASS="function" >start()</B > detects, that the user isn't already logged in, it starts the authentication mechanism: An HTML form is printed and the user can enter his login data. </P ><P > <B CLASS="function" >getAuth()</B > is a helper function that returns true if the user is logged and that returns false if he hasn't already logged in. </P ></DIV ></DIV ><?php manualFooter('','packages.auth.php'); ?> Index: pearweb/public_html/manual/packages.net_checkip.php +++ pearweb/public_html/manual/packages.net_checkip.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('packages.auth.php', ''), 'next' => array('index.php#AEN0', ''), 'up' => array('packages.php', 'PEAR Packages'), 'toc' => array( array('packages.php#packages', ''), array('packages.php#AEN0', ''), array('packages.skeleton.php', ''), array('packages.php#AEN0', ''), array('packages.auth.php', ''), array('packages.php#AEN0', ''), array('packages.net_checkip.php', '')))); manualHeader('','packages.net_checkip.php'); ?><DIV CLASS="ARTICLE" ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" ><A NAME="AEN454" >Net_CheckIP: Validation of IPv4 adresses</A ></H1 ><HR></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="packages.net_checkip.net_checkip" >Net_Checkip</A ></H1 ><P > This class can validate if a given string has a valid IPv4 syntax. </P ><P >Usage example:</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > require_once "Net_CheckIP/CheckIP.php"; if (Net_CheckIP::check_ip("your_ip_goes_here")) { // Syntax of the IP is ok } </PRE ></TD ></TR ></TABLE ><P > The function <B CLASS="function" >check_ip()</B > returns true, if the passed string has a valid IPv4 syntax. That means that it has to contain exactly 4 numbers between 0 and 255, which are all separated by a dot. </P ></DIV ></DIV ><?php manualFooter('','packages.net_checkip.php'); ?> Index: pearweb/public_html/manual/packages.php +++ pearweb/public_html/manual/packages.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('class.pear-error.php', 'PEAR_Error'), 'next' => array('packages.skeleton.php', ''), 'up' => array('index.php', 'PEAR Manual'), 'toc' => array( array('index.php#manual', ''), array('index.php#AEN0', ''), array('index.php#bookinfo', ''), array('index.php#AEN0', ''), array('preface.php', 'Preface'), array('getting-started.php', 'Getting Started'), array('packages.php', 'PEAR Packages')))); manualHeader('PEAR Packages','packages.php'); ?><DIV CLASS="PART" ><A NAME="packages" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >II. PEAR Packages</H1 ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="packages.skeleton.php" >Skeleton for creating PEAR docbook documentation</A ></DT ><DT ><A HREF="packages.auth.php" >Auth: creating authentication realms</A ></DT ><DT ><A HREF="packages.net_checkip.php" >Net_CheckIP: Validation of IPv4 adresses</A ></DT ></DL ></DIV ></DIV ></DIV ><?php manualFooter('PEAR Packages','packages.php'); ?> Index: pearweb/public_html/manual/packages.skeleton.php +++ pearweb/public_html/manual/packages.skeleton.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('packages.php', 'PEAR Packages'), 'next' => array('packages.auth.php', ''), 'up' => array('packages.php', 'PEAR Packages'), 'toc' => array( array('packages.php#packages', ''), array('packages.php#AEN0', ''), array('packages.skeleton.php', ''), array('packages.php#AEN0', ''), array('packages.auth.php', ''), array('packages.php#AEN0', ''), array('packages.net_checkip.php', '')))); manualHeader('','packages.skeleton.php'); ?><DIV CLASS="ARTICLE" ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" ><A NAME="AEN416" >Skeleton for creating PEAR docbook documentation</A ></H1 ><HR></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="packages.skeleton.classname" >Classname</A ></H1 ><P >This is a paragraph, where you can put text in.</P ><P ></P ><UL ><LI ><P >The first item in the itemized list</P ></LI ><LI ><P >An itemized list is comparable with >ul<>li<>/li<>/ul< in HTML </P ></LI ></UL ><P ><I CLASS="emphasis" >Emphase</I > something, could transform in cursive or bold in other formats like PDF or HTML </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > // Often, you have to add programing examples. // Everything between the CDATA-section is treaten "as is" // including tabs(!) go_ahead() ; </PRE ></TD ></TR ></TABLE ><P > <B CLASS="function" >This_is_a_functionname()</B > and <B CLASS="classname" >i_am_the_name_of_a_class</B > or do you want to describe a <TT CLASS="parameter" ><I >parameter</I ></TT >? </P ></DIV ></DIV ><?php manualFooter('','packages.skeleton.php'); ?> Index: pearweb/public_html/manual/preface.php +++ pearweb/public_html/manual/preface.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('index.php', 'PEAR Manual'), 'next' => array('getting-started.php', 'Getting Started'), 'up' => array('index.php', 'PEAR Manual'), 'toc' => array( array('index.php#manual', ''), array('index.php#AEN0', ''), array('index.php#bookinfo', ''), array('index.php#AEN0', ''), array('preface.php', 'Preface'), array('getting-started.php', 'Getting Started'), array('packages.php', 'PEAR Packages')))); manualHeader('Preface','preface.php'); ?><DIV CLASS="preface" ><H1 ><A NAME="preface" >Preface</A ></H1 ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="preface.php#about" >About this Manual</A ></DT ></DL ></DIV ><BLOCKQUOTE CLASS="ABSTRACT" ><DIV CLASS="abstract" ><A NAME="AEN21" ></A ><P ></P ><P > <SPAN CLASS="acronym" >PEAR</SPAN > is the PHP Extension and Application Repository. </P ><P ></P ></DIV ></BLOCKQUOTE ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="about" >About this Manual</A ></H1 ><P > This manual is written in <SPAN CLASS="acronym" >XML</SPAN > using the <A HREF="http://www.nwalsh.com/docbook/xml/" TARGET="_top" >DocBook XML DTD</A >, using <A HREF="http://www.jclark.com/dsssl/" TARGET="_top" ><SPAN CLASS="acronym" >DSSSL</SPAN ></A > (Document Style and Semantics Specification Language) for formatting. The tools used for formatting <SPAN CLASS="acronym" >HTML</SPAN > versions are <A HREF="http://www.jclark.com/jade/" TARGET="_top" >Jade</A >, written by <A HREF="http://www.jclark.com/bio.htm" TARGET="_top" >James Clark</A > and <A HREF="http://nwalsh.com/docbook/dsssl/" TARGET="_top" >The Modular DocBook Stylesheets</A > written by <A HREF="http://nwalsh.com/" TARGET="_top" >Norman Walsh</A >. </P ><P > It is based on the great work, the PHP documentation group has done in the past. </P ></DIV ></DIV ><?php manualFooter('Preface','preface.php'); ?> Index: pearweb/public_html/manual/reference.php +++ pearweb/public_html/manual/reference.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('standards.naming.php', 'Naming Conventions'), 'next' => array('class.pear.php', 'PEAR'), 'up' => array('getting-started.php', 'Getting Started'), 'toc' => array( array('getting-started.php#getting-started', ''), array('getting-started.php#AEN0', ''), array('introduction.php', 'Introduction'), array('getting-started.php#AEN0', ''), array('standards.php', 'Coding Standards'), array('getting-started.php#AEN0', ''), array('reference.php', 'PEAR')))); manualHeader('PEAR Reference Manual','reference.php'); ?><DIV CLASS="reference" ><A NAME="reference" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >I. PEAR Reference Manual</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN201" ></A ><P > This chapter contains reference documentation for PEAR components that are distributed with PHP. It is assumed that you are already familiar with objects and classes. </P ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="class.pear.php" >PEAR</A > — PEAR base class</DT ><DT ><A HREF="class.pear-error.php" >PEAR_Error</A > — PEAR error mechanism base class</DT ></DL ></DIV ></DIV ></DIV ><?php manualFooter('PEAR Reference Manual','reference.php'); ?> Index: pearweb/public_html/manual/standards.comments.php +++ pearweb/public_html/manual/standards.comments.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('standards.funcdef.php', 'Function Definitions'), 'next' => array('standards.including.php', 'Including Code'), 'up' => array('standards.php', 'Coding Standards'), 'toc' => array( array('standards.php#standards', ''), array('standards.php#AEN57', ''), array('standards.php#standards.indenting', 'Indenting'), array('standards.control.php', 'Control Structures'), array('standards.funcalls.php', 'Function Calls'), array('standards.funcdef.php', 'Function Definitions'), array('standards.comments.php', 'Comments'), array('standards.including.php', 'Including Code'), array('standards.tags.php', 'PHP Code Tags'), array('standards.header.php', 'Header Comment Blocks'), array('standards.cvs.php', 'Using CVS'), array('standards.exampleurls.php', 'Example URLs'), array('standards.naming.php', 'Naming Conventions')))); manualHeader('Comments','standards.comments.php'); ?><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="standards.comments" >Comments</A ></H1 ><P > Inline documentation for classes should follow the PHPDoc convention, similar to Javadoc. More information about PHPDoc can be found here: <A HREF="http://www.phpdoc.de/" TARGET="_top" >http://www.phpdoc.de/</A > </P ><P > Non-documentation comments are strongly encouraged. A general rule of thumb is that if you look at a section of code and think "Wow, I don't want to try and describe that", you need to comment it before you forget how it works. </P ><P > C style comments (/* */) and standard C++ comments (//) are both fine. Use of Perl/shell style comments (#) is discouraged. </P ></DIV ><?php manualFooter('Comments','standards.comments.php'); ?> Index: pearweb/public_html/manual/standards.control.php +++ pearweb/public_html/manual/standards.control.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('standards.php', 'Coding Standards'), 'next' => array('standards.funcalls.php', 'Function Calls'), 'up' => array('standards.php', 'Coding Standards'), 'toc' => array( array('standards.php#standards', ''), array('standards.php#AEN57', ''), array('standards.php#standards.indenting', 'Indenting'), array('standards.control.php', 'Control Structures'), array('standards.funcalls.php', 'Function Calls'), array('standards.funcdef.php', 'Function Definitions'), array('standards.comments.php', 'Comments'), array('standards.including.php', 'Including Code'), array('standards.tags.php', 'PHP Code Tags'), array('standards.header.php', 'Header Comment Blocks'), array('standards.cvs.php', 'Using CVS'), array('standards.exampleurls.php', 'Example URLs'), array('standards.naming.php', 'Naming Conventions')))); manualHeader('Control Structures','standards.control.php'); ?><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="standards.control" >Control Structures</A ></H1 ><P > These include if, for, while, switch, etc. Here is an example if statement, since it is the most complicated of them: <TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > if ((condition1) || (condition2)) { action1; } elseif ((condition3) && (condition4)) { action2; } else { defaultaction; } </PRE ></TD ></TR ></TABLE > </P ><P > Control statements should have one space between the control keyword and opening parenthesis, to distinguish them from function calls. </P ><P > You are strongly encouraged to always use curly braces even in situations where they are technically optional. Having them increases readability and decreases the likelihood of logic errors being introduced when new lines are added. </P ><P > For switch statements: <TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > switch (condition) { case 1: action1; break; case 2: action2; break; default: defaultaction; break; } </PRE ></TD ></TR ></TABLE > </P ></DIV ><?php manualFooter('Control Structures','standards.control.php'); ?> Index: pearweb/public_html/manual/standards.cvs.php +++ pearweb/public_html/manual/standards.cvs.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('standards.header.php', 'Header Comment Blocks'), 'next' => array('standards.exampleurls.php', 'Example URLs'), 'up' => array('standards.php', 'Coding Standards'), 'toc' => array( array('standards.php#standards', ''), array('standards.php#AEN57', ''), array('standards.php#standards.indenting', 'Indenting'), array('standards.control.php', 'Control Structures'), array('standards.funcalls.php', 'Function Calls'), array('standards.funcdef.php', 'Function Definitions'), array('standards.comments.php', 'Comments'), array('standards.including.php', 'Including Code'), array('standards.tags.php', 'PHP Code Tags'), array('standards.header.php', 'Header Comment Blocks'), array('standards.cvs.php', 'Using CVS'), array('standards.exampleurls.php', 'Example URLs'), array('standards.naming.php', 'Naming Conventions')))); manualHeader('Using CVS','standards.cvs.php'); ?><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="standards.cvs" >Using CVS</A ></H1 ><P > This section applies only to packages using CVS at cvs.php.net. </P ><P > Include the $Id: standards.cvs.php,v 1.1 2001/10/14 15:27:53 mj Exp $ CVS keyword in each file. As each file is edited, add this tag if it's not yet present (or replace existing forms such as "Last Modified:", etc.). </P ><P > The rest of this section assumes that you have basic knowledge about CVS tags and branches. </P ><P > CVS tags are used to label which revisions of the files in your package belong to a given release. Below is a list of the required and suggested CVS tags: <P ></P ><DIV CLASS="variablelist" ><DL ><DT >RELEASE_<TT CLASS="replaceable" ><I >n_n</I ></TT ></DT ><DD ><P > (required) Used for tagging a release. If you don't use it, there's no way to go back and retrieve your package from the CVS server in the state it was in at the time of the release. </P ></DD ><DT >QA_<TT CLASS="replaceable" ><I >n_n</I ></TT ></DT ><DD ><P > (branch, optional) If you feel you need to roll out a release candidate before releasing, it's a good idea to make a branch for it so you can isolate the release and apply only those critical fixes before the actual release. Meanwhile, normal development may continue on the main trunk. </P ></DD ><DT >MAINT_<TT CLASS="replaceable" ><I >n_n</I ></TT ></DT ><DD ><P > (branch, optional) If you need to make "micro-releases" (for example 1.2.1 and so on after 1.2), you can use a branch for that too, if your main trunk is very active and you want only minor changes between your micro-releases. </P ></DD ></DL ></DIV > Only the RELEASE tag is required, the rest are recommended for your convenience. </P ><P > Below is an example of how to tag the 1.2 release of the "Money_Fast" package: <DIV CLASS="informalexample" ><A NAME="AEN139" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="screen" ><TT CLASS="prompt" >$ </TT ><B CLASS="command" >cd pear/Money_Fast</B > <TT CLASS="prompt" >$ </TT ><B CLASS="command" >cvs tag RELEASE_1_2</B > <TT CLASS="computeroutput" >T Fast.php T README T package.xml </TT > </PRE ></TD ></TR ></TABLE ><P ></P ></DIV > By doing this you make it possible for the PEAR web site to take you through the rest of your release process. </P ><P > Here's an example of how to create a QA branch: <DIV CLASS="informalexample" ><A NAME="AEN147" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="screen" ><TT CLASS="prompt" >$ </TT ><B CLASS="command" >cvs tag QA_2_0_BP</B > ... <TT CLASS="prompt" >$ </TT ><B CLASS="command" >cvs rtag -b -r QA_2_0_BP QA_2_0</B > <TT CLASS="prompt" >$ </TT ><B CLASS="command" >cvs update -r QA_2_0</B > <TT CLASS="prompt" >$ </TT ><B CLASS="command" >cvs tag RELEASE_2_0RC1</B > ...and then the actual release, from the same branch: <TT CLASS="prompt" >$ </TT ><B CLASS="command" >cvs tag RELEASE_2_0</B > </PRE ></TD ></TR ></TABLE ><P ></P ></DIV > The "QA_2_0_BP" tag is a "branch point" tag, which is the start point of the tag. It's always a good idea to start a CVS branch from such branch points. MAINT branches may use the RELEASE tag as their branch point. </P ></DIV ><?php manualFooter('Using CVS','standards.cvs.php'); ?> Index: pearweb/public_html/manual/standards.exampleurls.php +++ pearweb/public_html/manual/standards.exampleurls.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('standards.cvs.php', 'Using CVS'), 'next' => array('standards.naming.php', 'Naming Conventions'), 'up' => array('standards.php', 'Coding Standards'), 'toc' => array( array('standards.php#standards', ''), array('standards.php#AEN57', ''), array('standards.php#standards.indenting', 'Indenting'), array('standards.control.php', 'Control Structures'), array('standards.funcalls.php', 'Function Calls'), array('standards.funcdef.php', 'Function Definitions'), array('standards.comments.php', 'Comments'), array('standards.including.php', 'Including Code'), array('standards.tags.php', 'PHP Code Tags'), array('standards.header.php', 'Header Comment Blocks'), array('standards.cvs.php', 'Using CVS'), array('standards.exampleurls.php', 'Example URLs'), array('standards.naming.php', 'Naming Conventions')))); manualHeader('Example URLs','standards.exampleurls.php'); ?><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="standards.exampleurls" >Example URLs</A ></H1 ><P > Use "example.com" for all example URLs, per RFC 2606. </P ></DIV ><?php manualFooter('Example URLs','standards.exampleurls.php'); ?> Index: pearweb/public_html/manual/standards.funcalls.php +++ pearweb/public_html/manual/standards.funcalls.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('standards.control.php', 'Control Structures'), 'next' => array('standards.funcdef.php', 'Function Definitions'), 'up' => array('standards.php', 'Coding Standards'), 'toc' => array( array('standards.php#standards', ''), array('standards.php#AEN57', ''), array('standards.php#standards.indenting', 'Indenting'), array('standards.control.php', 'Control Structures'), array('standards.funcalls.php', 'Function Calls'), array('standards.funcdef.php', 'Function Definitions'), array('standards.comments.php', 'Comments'), array('standards.including.php', 'Including Code'), array('standards.tags.php', 'PHP Code Tags'), array('standards.header.php', 'Header Comment Blocks'), array('standards.cvs.php', 'Using CVS'), array('standards.exampleurls.php', 'Example URLs'), array('standards.naming.php', 'Naming Conventions')))); manualHeader('Function Calls','standards.funcalls.php'); ?><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="standards.funcalls" >Function Calls</A ></H1 ><P > Functions should be called with no spaces between the function name, the opening parenthesis, and the first parameter; spaces between commas and each parameter, and no space between the last parameter, the closing parenthesis, and the semicolon. Here's an example: <TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > $var = foo($bar, $baz, $quux); </PRE ></TD ></TR ></TABLE > </P ><P > As displayed above, there should be one space on either side of an equals sign used to assign the return value of a function to a variable. In the case of a block of related assignments, more space may be inserted to promote readability: <TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > $short = foo($bar); $long_variable = foo($baz); </PRE ></TD ></TR ></TABLE > </P ></DIV ><?php manualFooter('Function Calls','standards.funcalls.php'); ?> Index: pearweb/public_html/manual/standards.funcdef.php +++ pearweb/public_html/manual/standards.funcdef.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('standards.funcalls.php', 'Function Calls'), 'next' => array('standards.comments.php', 'Comments'), 'up' => array('standards.php', 'Coding Standards'), 'toc' => array( array('standards.php#standards', ''), array('standards.php#AEN57', ''), array('standards.php#standards.indenting', 'Indenting'), array('standards.control.php', 'Control Structures'), array('standards.funcalls.php', 'Function Calls'), array('standards.funcdef.php', 'Function Definitions'), array('standards.comments.php', 'Comments'), array('standards.including.php', 'Including Code'), array('standards.tags.php', 'PHP Code Tags'), array('standards.header.php', 'Header Comment Blocks'), array('standards.cvs.php', 'Using CVS'), array('standards.exampleurls.php', 'Example URLs'), array('standards.naming.php', 'Naming Conventions')))); manualHeader('Function Definitions','standards.funcdef.php'); ?><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="standards.funcdef" >Function Definitions</A ></H1 ><P > Function declaractions follow the "one true brace" convention: <TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > function fooFunction($arg1, $arg2 = '') { if (condition) { statement; } return $val; } </PRE ></TD ></TR ></TABLE > </P ><P > Arguments with default values go at the end of the argument list. Always attempt to return a meaningful value from a function if one is appropriate. Here is a slightly longer example: <TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > function connect(&$dsn, $persistent = false) { if (is_array($dsn)) { $dsninfo = &$dsn; } else { $dsninfo = DB::parseDSN($dsn); } if (!$dsninfo || !$dsninfo['phptype']) { return $this->raiseError(); } return true; } </PRE ></TD ></TR ></TABLE > </P ></DIV ><?php manualFooter('Function Definitions','standards.funcdef.php'); ?> Index: pearweb/public_html/manual/standards.header.php +++ pearweb/public_html/manual/standards.header.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('standards.tags.php', 'PHP Code Tags'), 'next' => array('standards.cvs.php', 'Using CVS'), 'up' => array('standards.php', 'Coding Standards'), 'toc' => array( array('standards.php#standards', ''), array('standards.php#AEN57', ''), array('standards.php#standards.indenting', 'Indenting'), array('standards.control.php', 'Control Structures'), array('standards.funcalls.php', 'Function Calls'), array('standards.funcdef.php', 'Function Definitions'), array('standards.comments.php', 'Comments'), array('standards.including.php', 'Including Code'), array('standards.tags.php', 'PHP Code Tags'), array('standards.header.php', 'Header Comment Blocks'), array('standards.cvs.php', 'Using CVS'), array('standards.exampleurls.php', 'Example URLs'), array('standards.naming.php', 'Naming Conventions')))); manualHeader('Header Comment Blocks','standards.header.php'); ?><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="standards.header" >Header Comment Blocks</A ></H1 ><P > All source code files in the core PEAR distribution should contain the following comment block as the header: <TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4.0 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Original Author <author@example.com> | // | Your Name <you@example.com> | // +----------------------------------------------------------------------+ // // $Id: standards.header.php,v 1.1 2001/10/14 15:27:53 mj Exp $ </PRE ></TD ></TR ></TABLE > </P ><P > There's no hard rule to determine when a new code contributer should be added to the list of authors for a given source file. In general, their changes should fall into the "substantial" category (meaning somewhere around 10% to 20% of code changes). Exceptions could be made for rewriting functions or contributing new logic. </P ><P > Simple code reorganization or bug fixes would not justify the addition of a new individual to the list of authors. </P ><P > Files not in the core PEAR repository should have a similar block stating the copyright, the license, and the authors. All files should include the modeline comments to encourage consistency. </P ></DIV ><?php manualFooter('Header Comment Blocks','standards.header.php'); ?> Index: pearweb/public_html/manual/standards.including.php +++ pearweb/public_html/manual/standards.including.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('standards.comments.php', 'Comments'), 'next' => array('standards.tags.php', 'PHP Code Tags'), 'up' => array('standards.php', 'Coding Standards'), 'toc' => array( array('standards.php#standards', ''), array('standards.php#AEN57', ''), array('standards.php#standards.indenting', 'Indenting'), array('standards.control.php', 'Control Structures'), array('standards.funcalls.php', 'Function Calls'), array('standards.funcdef.php', 'Function Definitions'), array('standards.comments.php', 'Comments'), array('standards.including.php', 'Including Code'), array('standards.tags.php', 'PHP Code Tags'), array('standards.header.php', 'Header Comment Blocks'), array('standards.cvs.php', 'Using CVS'), array('standards.exampleurls.php', 'Example URLs'), array('standards.naming.php', 'Naming Conventions')))); manualHeader('Including Code','standards.including.php'); ?><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="standards.including" >Including Code</A ></H1 ><P > Anywhere you are unconditionally including a class file, use <B CLASS="function" >require_once()</B >. Anywhere you are conditionally including a class file (for example, factory methods), use <B CLASS="function" >include_once()</B >. Either of these will ensure that class files are included only once. They share the same file list, so you don't need to worry about mixing them - a file included with <B CLASS="function" >require_once()</B > will not be included again by <B CLASS="function" >include_once()</B >. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > <B CLASS="function" >include_once()</B > and <B CLASS="function" >require_once()</B > are statements, not functions. You don't <I CLASS="emphasis" >need</I > parentheses around the filename to be included. </P ></BLOCKQUOTE ></DIV > </P ></DIV ><?php manualFooter('Including Code','standards.including.php'); ?> Index: pearweb/public_html/manual/standards.naming.php +++ pearweb/public_html/manual/standards.naming.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('standards.exampleurls.php', 'Example URLs'), 'next' => array('reference.php', 'PEAR'), 'up' => array('standards.php', 'Coding Standards'), 'toc' => array( array('standards.php#standards', ''), array('standards.php#AEN57', ''), array('standards.php#standards.indenting', 'Indenting'), array('standards.control.php', 'Control Structures'), array('standards.funcalls.php', 'Function Calls'), array('standards.funcdef.php', 'Function Definitions'), array('standards.comments.php', 'Comments'), array('standards.including.php', 'Including Code'), array('standards.tags.php', 'PHP Code Tags'), array('standards.header.php', 'Header Comment Blocks'), array('standards.cvs.php', 'Using CVS'), array('standards.exampleurls.php', 'Example URLs'), array('standards.naming.php', 'Naming Conventions')))); manualHeader('Naming Conventions','standards.naming.php'); ?><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="standards.naming" >Naming Conventions</A ></H1 ><DIV CLASS="sect2" ><H2 CLASS="sect2" ><A NAME="AEN164" >Functions and Methods</A ></H2 ><P > Functions and methods should be named using the "studly caps" style (also referred to as "bumpy case" or "camel caps"). Functions should in addition have the package name as a prefix, to avoid name collisions between packages. The initial letter of the name (after the prefix) is lowercase, and each letter that starts a new "word" is capitalized. Some examples: <DIV CLASS="informaltable" ><A NAME="AEN167" ></A ><P ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><P >connect()</P ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><P >getData()</P ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><P >buildSomeWidget()</P ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><P >XML_RPC_serializeData()</P ></TD ></TR ></TBODY ></TABLE ><P ></P ></DIV > </P ><P > Private class members (meaning class members that are intented to be used only from within the same class in which they are declared; PHP does not yet support truly-enforceable private namespaces) are preceeded by a single underscore. For example: <DIV CLASS="informaltable" ><A NAME="AEN180" ></A ><P ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><P >_sort()</P ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><P >_initTree()</P ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><P >$this->_status</P ></TD ></TR ></TBODY ></TABLE ><P ></P ></DIV > </P ></DIV ><DIV CLASS="sect2" ><H2 CLASS="sect2" ><A NAME="AEN190" >Constants</A ></H2 ><P > Constants should always be all-uppercase, with underscores to seperate words. Prefix constant names with the uppercased name of the class/package they are used in. For example, the constants used by the <TT CLASS="literal" >DB::</TT > package all begin with "<TT CLASS="literal" >DB_</TT >". </P ></DIV ><DIV CLASS="sect2" ><H2 CLASS="sect2" ><A NAME="AEN195" >Global Variables</A ></H2 ><P > If your package needs to define global variables, their name should start with a single underscore followed by the package name and another underscore. For example, the PEAR package uses a global variable called $_PEAR_destructor_object_list. </P ></DIV ></DIV ><?php manualFooter('Naming Conventions','standards.naming.php'); ?> Index: pearweb/public_html/manual/standards.php +++ pearweb/public_html/manual/standards.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('introduction.php', 'Introduction'), 'next' => array('standards.control.php', 'Control Structures'), 'up' => array('getting-started.php', 'Getting Started'), 'toc' => array( array('getting-started.php#getting-started', ''), array('getting-started.php#AEN0', ''), array('introduction.php', 'Introduction'), array('getting-started.php#AEN0', ''), array('standards.php', 'Coding Standards'), array('getting-started.php#AEN0', ''), array('reference.php', 'PEAR')))); manualHeader('Coding Standards','standards.php'); ?><DIV CLASS="chapter" ><H1 ><A NAME="standards" >Chapter 2. Coding Standards</A ></H1 ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="standards.php#standards.indenting" >Indenting</A ></DT ><DT ><A HREF="standards.control.php" >Control Structures</A ></DT ><DT ><A HREF="standards.funcalls.php" >Function Calls</A ></DT ><DT ><A HREF="standards.funcdef.php" >Function Definitions</A ></DT ><DT ><A HREF="standards.comments.php" >Comments</A ></DT ><DT ><A HREF="standards.including.php" >Including Code</A ></DT ><DT ><A HREF="standards.tags.php" >PHP Code Tags</A ></DT ><DT ><A HREF="standards.header.php" >Header Comment Blocks</A ></DT ><DT ><A HREF="standards.cvs.php" >Using CVS</A ></DT ><DT ><A HREF="standards.exampleurls.php" >Example URLs</A ></DT ><DT ><A HREF="standards.naming.php" >Naming Conventions</A ></DT ></DL ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > The PEAR Coding Standards applies to code that is to become a part of PEAR, either distributed with PHP or available for download via PEAR's install tool. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="standards.indenting" >Indenting</A ></H1 ><P > Use an indent of 4 spaces, with no tabs. If you use Emacs to edit PEAR code, you should set indent-tabs-mode to nil. Here is an example mode hook that will set up Emacs according to these guidelines (you will need to ensure that it is called when you are editing PHP files): <TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > (defun php-mode-hook () (setq tab-width 4 c-basic-offset 4 c-hanging-comment-ender-p nil indent-tabs-mode (not (and (string-match "/\\(PEAR\\|pear\\)/" (buffer-file-name)) (string-match "\.php$" (buffer-file-name)))))) </PRE ></TD ></TR ></TABLE > </P ><P >Here are vim rules for the same thing: <TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > set expandtab set shiftwidth=4 set tabstop=4 </PRE ></TD ></TR ></TABLE > </P ></DIV ></DIV ><?php manualFooter('Coding Standards','standards.php'); ?> Index: pearweb/public_html/manual/standards.tags.php +++ pearweb/public_html/manual/standards.tags.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('standards.including.php', 'Including Code'), 'next' => array('standards.header.php', 'Header Comment Blocks'), 'up' => array('standards.php', 'Coding Standards'), 'toc' => array( array('standards.php#standards', ''), array('standards.php#AEN57', ''), array('standards.php#standards.indenting', 'Indenting'), array('standards.control.php', 'Control Structures'), array('standards.funcalls.php', 'Function Calls'), array('standards.funcdef.php', 'Function Definitions'), array('standards.comments.php', 'Comments'), array('standards.including.php', 'Including Code'), array('standards.tags.php', 'PHP Code Tags'), array('standards.header.php', 'Header Comment Blocks'), array('standards.cvs.php', 'Using CVS'), array('standards.exampleurls.php', 'Example URLs'), array('standards.naming.php', 'Naming Conventions')))); manualHeader('PHP Code Tags','standards.tags.php'); ?><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="standards.tags" >PHP Code Tags</A ></H1 ><P > <I CLASS="emphasis" >Always</I > use <TT CLASS="literal" ><?php ?></TT > to delimit PHP code, not the <TT CLASS="literal" ><? ?></TT > shorthand. This is required for PEAR compliance and is also the most portable way to include PHP code on differing operating systems and setups. </P ></DIV ><?php manualFooter('PHP Code Tags','standards.tags.php'); ?>
Index: pearweb/public_html/manual/class.pear-error.php +++ pearweb/public_html/manual/class.pear-error.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('class.pear.php', 'PEAR'), 'next' => array('packages.php', 'PEAR Packages'), 'up' => array('reference.php', 'PEAR'), 'toc' => array( array('reference.php#reference', ''), array('reference.php#AEN200', ''), array('reference.php#AEN201', ''), array('class.pear.php', 'PEAR'), array('class.pear-error.php', 'PEAR_Error')))); manualHeader('PEAR_Error','class.pear-error.php'); ?><H1 ><A NAME="class.pear-error" >PEAR_Error</A ></H1 ><DIV CLASS="refnamediv" ><A NAME="AEN338" ></A >PEAR_Error -- PEAR error mechanism base class</DIV ><DIV CLASS="refsynopsisdiv" ><A NAME="AEN341" ></A ><H2 >Synopsis</H2 ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="synopsis" >$err = new PEAR_Error($msg);</PRE ></TD ></TR ></TABLE ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN344" ></A ><H2 >Error Modes</H2 ><P > An error object has a mode of operation that can be set with one of the following constants: <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="constant.pear-error-return" >PEAR_ERROR_RETURN</A ></DT ><DD ><P > Just return the object, don't do anything special in PEAR_Error's constructor. </P ></DD ><DT ><A NAME="constant.pear-error-print" >PEAR_ERROR_PRINT</A ></DT ><DD ><P > Print the error message in the constructor. The execution is not interrupted. </P ></DD ><DT ><A NAME="constant.pear-error-trigger" >PEAR_ERROR_TRIGGER</A ></DT ><DD ><P > Use PHP's <B CLASS="function" >trigger_error()</B > function to raise an internal error in PHP. The execution is aborted if you have defined your own PHP error handler or if you set the error severity to E_USER_ERROR. </P ></DD ><DT ><A NAME="constant.pear-error-die" >PEAR_ERROR_DIE</A ></DT ><DD ><P > Print the error message and exit. Execution is of course aborted. </P ></DD ><DT ><A NAME="constant.pear-error-callback" >PEAR_ERROR_CALLBACK</A ></DT ><DD ><P > Use a callback function or method to handle errors. Execution is aborted. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN369" ></A ><H2 >Properties</H2 ><P ></P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN372" ></A ><H2 >Methods</H2 ><DIV CLASS="funcsynopsis" ><A NAME="AEN374" ></A ><P ></P ><P ><CODE ><CODE CLASS="FUNCDEF" ><B CLASS="function" >PEAR_Error::PEAR_Error</B ></CODE > ([message code mode options userinfo]]]]])</CODE ></P ><P ></P ></DIV ><DIV CLASS="refsect2" ><A NAME="AEN389" ></A ><H3 >Description</H3 ><P > PEAR_Error constructor. Parameters: <P ></P ><DIV CLASS="variablelist" ><DL ><DT >message</DT ><DD ><P > error message, defaults to "unknown error" </P ></DD ><DT >code</DT ><DD ><P > error code (optional) </P ></DD ><DT >mode</DT ><DD ><P > Mode of operation. See the <A HREF="class.pear-error.php#error-modes" >error modes</A > section for details. </P ></DD ><DT >options</DT ><DD ><P > If the mode of can have any options specified, use this parameter. Currently the "trigger" and "callback" modes are the only using the options parameter. For trigger mode, this parameter is one of <TT CLASS="constant" ><B >E_USER_NOTICE</B ></TT >, <TT CLASS="constant" ><B >E_USER_WARNING</B ></TT > or <TT CLASS="constant" ><B >E_USER_ERROR</B ></TT >. For callback mode, this parameter should contain either the callback function name (string), or a two-element (object, string) array representing an object and a method name. </P ></DD ></DL ></DIV > </P ></DIV ></DIV ><?php manualFooter('PEAR_Error','class.pear-error.php'); ?> Index: pearweb/public_html/manual/class.pear.php +++ pearweb/public_html/manual/class.pear.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('reference.php', 'PEAR'), 'next' => array('class.pear-error.php', 'PEAR_Error'), 'up' => array('reference.php', 'PEAR'), 'toc' => array( array('reference.php#reference', ''), array('reference.php#AEN200', ''), array('reference.php#AEN201', ''), array('class.pear.php', 'PEAR'), array('class.pear-error.php', 'PEAR_Error')))); manualHeader('PEAR','class.pear.php'); ?><H1 ><A NAME="class.pear" >PEAR</A ></H1 ><DIV CLASS="refnamediv" ><A NAME="AEN205" ></A >PEAR -- PEAR base class</DIV ><DIV CLASS="refsynopsisdiv" ><A NAME="AEN208" ></A ><H2 >Synopsis</H2 ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="synopsis" >require_once "PEAR.php";</PRE ></TD ></TR ></TABLE ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="synopsis" >class <TT CLASS="replaceable" ><I >classname</I ></TT > extends PEAR { ... }</PRE ></TD ></TR ></TABLE ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN213" ></A ><H2 >Description</H2 ><P > The PEAR base class provides standard functionality that is used by most PEAR classes. Normally you never make an instance of the PEAR class directly, you use it by subclassing it. </P ><P > Its key features are: <P ></P ><UL ><LI ><P >request-shutdown object "destructors"</P ></LI ><LI ><P >error handling</P ></LI ></UL > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="destructors" ></A ><H2 >PEAR "destructors"</H2 ><P > If you inherit <A HREF="class.pear.php" ><B CLASS="classname" >PEAR</B ></A > in a class called <TT CLASS="replaceable" ><I >ClassName</I ></TT >, you can define a method in it called called _<TT CLASS="replaceable" ><I >ClassName</I ></TT > (the class name with an underscore prepended) that will be invoked when the request is over. This is not a destructor in the sense that you can "delete" an object and have the destructor called, but in the sense that PHP gives you a callback in the object when PHP is done executing. See <A HREF="class.pear.php#example.destructors" >the example</A > below. </P ><P > <DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B ><A NAME="destructors.warning" ></A >Important!</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > In order for destructors to work properly, you must instantiate your class with the "=& new" operator like this: <TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > $obj =& new MyClass(); </PRE ></TD ></TR ></TABLE > </P ><P > If you only use "= new", the object registered in PEAR's shutdown list will be a copy of the object at the time the constructor is called, and it will this copy's "destructor" that will be called upon request shutdown. </P ></TD ></TR ></TABLE ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="error-handling" ></A ><H2 >PEAR Error Handling</H2 ><P > PEAR's base class also provides a way of passing around more complex errors than a true/false value or a numeric code. A PEAR error is an object that is either an instance of the class <A HREF="class.pear-error.php" ><B CLASS="classname" >PEAR_Error</B ></A >, or some class inheriting <A HREF="class.pear-error.php" ><B CLASS="classname" >PEAR_Error</B ></A >. </P ><P > One of the design criteria of PEAR's errors is that it should not force a particular type of output on the user, it should be possible to handle errors without any output at all if that is desirable. This makes it possible to handle errors gracefully, also when your output format is different from HTML (for example WML or some other XML format). </P ><P > The error object can be configured to do a number of things when it is created, such as printing an error message, printing the message and exiting, raising an error with PHP's <B CLASS="function" >trigger_error()</B > function, invoke a callback, or none of the above. This is typically specified in <A HREF="class.pear-error.php" ><B CLASS="classname" >PEAR_Error</B ></A >'s constructor, but all of the parameters are optional, and you can set up defaults for errors generated from each object based on the <A HREF="class.pear.php" ><B CLASS="classname" >PEAR</B ></A > class. See the <A HREF="class.pear.php#example.error1" >PEAR error examples</A > for how to use it and the <A HREF="class.pear-error.php" ><B CLASS="classname" >PEAR_Error</B ></A > reference for the full details. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN247" ></A ><H2 >Examples</H2 ><P > The example below shows how to use the PEAR's "poor man's kinda emulated destructors" to implement a simple class that holds the contents of a file, lets you append data to the object and flushes the data back to the file at the end of the request: <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="example.destructors" ></A ><P ><B >Example 1. PEAR: emulated destructors</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > require_once "PEAR.php"; class FileContainer extends PEAR { var $file = ''; var $contents = ''; var $modified = 0; function FileContainer($file) { $this->PEAR(); // this calls the parent class constructor $fp = fopen($file, "r"); if (!is_resource($fp)) { return; } while (!empty($data = fread($fp, 2048))) { $this->contents .= $data; } fclose($fp); } function append($str) { $this->contents .= $str; $this->modified++; } // The "destructor" is named like the constructor // but with an underscore in front. function _FileContainer() { if ($this->modified) { $fp = fopen($this->file, "w"); if (!is_resource($fp)) { return; } fwrite($fp, $this->contents); fclose($fp); } } } $fileobj =& new FileContainer("testfile"); $fileobj->append("this ends up at the end of the file\n"); // When the request is done and PHP shuts down, $fileobj's // "destructor" is called and updates the file on disk. </PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > PEAR "destructors" use PHP's shutdown callbacks (<B CLASS="function" >register_shutdown_function()</B >), and you can't output anything from these when PHP is running in a web server. So anything printed in a "destructor" gets lost except when PHP is used in command-line mode. Bummer. </P ><P > Also, see the <A HREF="class.pear.php#destructors.warning" >warning</A > about how to instantiate objects if you want to use the destructor. </P ></BLOCKQUOTE ></DIV > </P ><P > The next examples illustrate different ways of using PEAR's error handling mechanism. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="example.error1" ></A ><P ><B >Example 2. PEAR error example (1)</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > function mysockopen($host = "localhost", $port = 8090) { $fp = fsockopen($host, $port, $errno, $errstr); if (!is_resource($fp)) { return new PEAR_Error($errstr, $errno); } return $fp; } $sock = mysockopen(); if (PEAR::isError($sock)) { print "mysockopen error: ".$sock->getMessage()."<BR>\n" } </PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > This example shows a wrapper to <B CLASS="function" >fsockopen()</B > that delivers the error code and message (if any) returned by fsockopen in a PEAR error object. Notice that <B CLASS="function" >PEAR::isError()</B > is used to detect whether a value is a PEAR error. </P ><P > PEAR_Error's mode of operation in this example is simply returning the error object and leaving the rest to the user (programmer). This is the default error mode. </P ><P > In the next example we're showing how to use default error modes: </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="example.error2" ></A ><P ><B >Example 3. PEAR error example (2)</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > class TCP_Socket extends PEAR { var $sock; function TCP_Socket() { $this->PEAR(); } function connect($host, $port) { $sock = fsockopen($host, $port, $errno, $errstr); if (!is_resource($sock)) { return $this->raiseError($errstr, $errno); } } } $sock = new TCP_Socket; $sock->setErrorHandling(PEAR_ERROR_DIE); $sock->connect("localhost", 8090); print "still alive<BR>\n"; </PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > Here, we set the default error mode to <A HREF="class.pear-error.php#constant.pear-error-die" ><TT CLASS="constant" ><B >PEAR_ERROR_DIE</B ></TT ></A >, and since we don't specify any error mode in the raiseError call (that'd be the third parameter), raiseError uses the default error mode and exits if fsockopen fails. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN274" ></A ><H2 >Global Variables Used</H2 ><P > The PEAR class uses some global variables to register global defaults, and an object list used by the "destructors". All of the global variables associated with the PEAR class have a <TT CLASS="literal" >_PEAR_</TT > name prefix. </P ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT >$_PEAR_default_error_mode</DT ><DD ><P > If no default error mode is set in an object, this mode will be used. Must be one of <A HREF="class.pear-error.php#constant.pear-error-return" ><TT CLASS="constant" ><B >PEAR_ERROR_RETURN</B ></TT ></A >, <A HREF="class.pear-error.php#constant.pear-error-print" ><TT CLASS="constant" ><B >PEAR_ERROR_PRINT</B ></TT ></A >, <A HREF="class.pear-error.php#constant.pear-error-trigger" ><TT CLASS="constant" ><B >PEAR_ERROR_TRIGGER</B ></TT ></A >, <A HREF="class.pear-error.php#constant.pear-error-die" ><TT CLASS="constant" ><B >PEAR_ERROR_DIE</B ></TT ></A > or <A HREF="class.pear-error.php#constant.pear-error-callback" ><TT CLASS="constant" ><B >PEAR_ERROR_CALLBACK</B ></TT ></A >. </P ><P > Don't set this variable directly, call <B CLASS="function" >PEAR::setErrorHandling()</B > as a static method like this: <DIV CLASS="informalexample" ><A NAME="AEN291" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > PEAR::setErrorHandling(PEAR_ERROR_DIE); </PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DD ><DT >$_PEAR_default_error_options</DT ><DD ><P > If the error mode is <A HREF="class.pear-error.php#constant.pear-error-trigger" ><TT CLASS="constant" ><B >PEAR_ERROR_TRIGGER</B ></TT ></A >, this is the error level (one of <TT CLASS="constant" ><B >E_USER_NOTICE</B ></TT >, <TT CLASS="constant" ><B >E_USER_WARNING</B ></TT > or <TT CLASS="constant" ><B >E_USER_ERROR</B ></TT >). </P ><P > Don't set this variable directly, call <B CLASS="function" >PEAR::setErrorHandling()</B > as a static method like this: <DIV CLASS="informalexample" ><A NAME="AEN303" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > PEAR::setErrorHandling(PEAR_ERROR_TRIGGER, E_USER_ERROR); </PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DD ><DT >$_PEAR_default_error_callback</DT ><DD ><P > If no <TT CLASS="replaceable" ><I >options</I ></TT > parameter is used when an error is raised and the error mode is <A HREF="class.pear-error.php#constant.pear-error-callback" ><TT CLASS="constant" ><B >PEAR_ERROR_CALLBACK</B ></TT ></A >, the value of this variable is used as the callback. This means that you can switch the error mode temporarily and return to callback mode without specifying the callback function again. A string value represents a function, a two-element array with an object at index 0 and a string at index 1 represents a method. </P ><P > Again, don't set this variable directly, call <B CLASS="function" >PEAR::setErrorHandling()</B > as a static method like this: <DIV CLASS="informalexample" ><A NAME="AEN313" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, "my_error_handler"); </PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P > Here is an example of how you can switch back and forth without specifying the callback function again: <DIV CLASS="informalexample" ><A NAME="AEN316" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > PEAR::setErrorMode(PEAR_ERROR_CALLBACK, "my_function_handler"); do_some_stuff(); PEAR::setErrorMode(PEAR_ERROR_DIE); do_some_critical_stuff(); PEAR::setErrorMode(PEAR_ERROR_CALLBACK); // now we're back to using my_function_handler again </PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN318" ></A ><H2 >Methods</H2 ><DIV CLASS="refsect2" ><A NAME="function.pear" ></A ><H3 >PEAR::PEAR</H3 ><DIV CLASS="funcsynopsis" ><A NAME="AEN322" ></A ><P ></P ><P ><CODE ><CODE CLASS="FUNCDEF" >PEAR()</CODE > (void)</CODE ></P ><P ></P ></DIV ><P > This is the PEAR class constructor. Call it from the constructor of every class inheriting the PEAR class. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN327" ></A ><P ><B >Example 4. PEAR Class Constructor Example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > class MyClass extends PEAR { var $foo, $bar; function MyClass($foo, $bar) { $this->PEAR(); $this->foo = $foo; $this->bar = $bar; } } </PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="refsect2" ><A NAME="function.-pear" ></A ><H3 >PEAR::_PEAR</H3 ><DIV CLASS="funcsynopsis" ><A NAME="AEN332" ></A ><P ></P ><P ><CODE ><CODE CLASS="FUNCDEF" >_PEAR()</CODE > (void)</CODE ></P ><P ></P ></DIV ><P > This is the PEAR class destructor. It is called during request shutdown. </P ></DIV ></DIV ><?php manualFooter('PEAR','class.pear.php'); ?> Index: pearweb/public_html/manual/copyright.php +++ pearweb/public_html/manual/copyright.php <HTML ><HEAD ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.60"><LINK REL="HOME" TITLE="PEAR Manual" HREF="index.php"><LINK REL="NEXT" TITLE="Preface" HREF="preface.php"></HEAD ><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PEAR Manual</TH ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="legalnotice" ><A NAME="copyright" ></A ><P ><B >Copyright</B ></P ><P > This manual is © Copyright 2001 by the PHP PEAR Group. The members of this group are listed on the front page of this manual. </P ><P > This manual can be redistributed under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" > </TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.php" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" > </TD ></TR ></TABLE ></DIV ></BODY ></HTML > Index: pearweb/public_html/manual/getting-started.php +++ pearweb/public_html/manual/getting-started.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('preface.php', 'Preface'), 'next' => array('introduction.php', 'Introduction'), 'up' => array('index.php', 'PEAR Manual'), 'toc' => array( array('index.php#manual', ''), array('index.php#AEN0', ''), array('index.php#bookinfo', ''), array('index.php#AEN0', ''), array('preface.php', 'Preface'), array('getting-started.php', 'Getting Started'), array('packages.php', 'PEAR Packages')))); manualHeader('Getting Started','getting-started.php'); ?><DIV CLASS="PART" ><A NAME="getting-started" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >I. Getting Started</H1 ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT >1. <A HREF="introduction.php" >Introduction</A ></DT ><DT >2. <A HREF="standards.php" >Coding Standards</A ></DT ><DT >I. <A HREF="reference.php" >PEAR Reference Manual</A ></DT ></DL ></DIV ></DIV ></DIV ><?php manualFooter('Getting Started','getting-started.php'); ?> Index: pearweb/public_html/manual/index.php +++ pearweb/public_html/manual/index.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('index.php#AEN0', ''), 'next' => array('preface.php', 'Preface'), 'up' => array('index.php#AEN0', ''), 'toc' => array( array('index.php#AEN0', '')))); manualHeader('PEAR Manual','index.php'); ?><DIV CLASS="BOOK" ><A NAME="manual" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" ><A NAME="manual" >PEAR Manual</A ></H1 ><DIV CLASS="author" >Martin Jansen</DIV ><H4 CLASS="EDITEDBY" >Edited by</H4 ><H3 CLASS="editor" >Martin Jansen</H3 ><P CLASS="copyright" ><A HREF="copyright.php" >Copyright</A > © 2001 by the PHP PEAR Group</P ><HR></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="preface.php" >Preface</A ></DT ><DD ><DL ><DT ><A HREF="preface.php#about" >About this Manual</A ></DT ></DL ></DD ><DT >I. <A HREF="getting-started.php" >Getting Started</A ></DT ><DD ><DL ><DT >1. <A HREF="introduction.php" >Introduction</A ></DT ><DT >2. <A HREF="standards.php" >Coding Standards</A ></DT ><DT >I. <A HREF="reference.php" >PEAR Reference Manual</A ></DT ></DL ></DD ><DT >II. <A HREF="packages.php" >PEAR Packages</A ></DT ><DD ><DL ><DT ><A HREF="packages.skeleton.php" >Skeleton for creating PEAR docbook documentation</A ></DT ><DT ><A HREF="packages.auth.php" >Auth: creating authentication realms</A ></DT ><DT ><A HREF="packages.net_checkip.php" >Net_CheckIP: Validation of IPv4 adresses</A ></DT ></DL ></DD ></DL ></DIV ></DIV ><?php manualFooter('PEAR Manual','index.php'); ?> Index: pearweb/public_html/manual/introduction.php +++ pearweb/public_html/manual/introduction.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('getting-started.php', 'Getting Started'), 'next' => array('standards.php', 'Coding Standards'), 'up' => array('getting-started.php', 'Getting Started'), 'toc' => array( array('getting-started.php#getting-started', ''), array('getting-started.php#AEN0', ''), array('introduction.php', 'Introduction'), array('getting-started.php#AEN0', ''), array('standards.php', 'Coding Standards'), array('getting-started.php#AEN0', ''), array('reference.php', 'PEAR')))); manualHeader('Introduction','introduction.php'); ?><DIV CLASS="chapter" ><H1 ><A NAME="introduction" >Chapter 1. Introduction</A ></H1 ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="introduction.php#pear-whatis" >What is PEAR?</A ></DT ></DL ></DIV ><P > PEAR is dedicated to Malin Bakken, born 1999-11-21 (the first PEAR code was written just two hours before she was born). </P ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="pear-whatis" >What is PEAR?</A ></H1 ><P > PEAR is a code repository for PHP extensions and PHP library code inspired by TeX's CTAN and Perl's CPAN. </P ><P > The purpose of PEAR is: <P ></P ><UL ><LI ><P > to provide a consistent means for library code authors to share their code with other developers </P ></LI ><LI ><P > to give the PHP community an infrastructure for sharing code </P ></LI ><LI ><P > to define standards that help developers write portable and reusable code </P ></LI ><LI ><P > to provide tools for code maintenance and distribution </P ></LI ></UL > </P ></DIV ></DIV ><?php manualFooter('Introduction','introduction.php'); ?> Index: pearweb/public_html/manual/packages.auth.php +++ pearweb/public_html/manual/packages.auth.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('packages.skeleton.php', ''), 'next' => array('packages.net_checkip.php', ''), 'up' => array('packages.php', 'PEAR Packages'), 'toc' => array( array('packages.php#packages', ''), array('packages.php#AEN0', ''), array('packages.skeleton.php', ''), array('packages.php#AEN0', ''), array('packages.auth.php', ''), array('packages.php#AEN0', ''), array('packages.net_checkip.php', '')))); manualHeader('','packages.auth.php'); ?><DIV CLASS="ARTICLE" ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" ><A NAME="AEN435" >Auth: creating authentication realms</A ></H1 ><HR></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="packages.auth.auth" >Auth</A ></H1 ><P >The PEAR Auth package helps you to create PHP based authentication systems.</P ><P >The biggest advantage of PEAR Auth is the fact, that it uses storage containers to read/write the login data. This containers can be easily docked into the auth system and can theoretically access to databases, files, LDAP servers etc. </P ><P >Usage example:</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > require_once "Auth/Auth.php"; $auth = new Auth("DB", "mysql://martin:test@localhost/test"); $auth->start(); if ($auth->getAuth()) { echo "You are successfully logged in. Welcome to the system.\n"; echo "This text is only visible for you because you are logged in.\n"; } </PRE ></TD ></TR ></TABLE ><P > The function <B CLASS="function" >Auth()</B > is the constructor of the Auth class. You can pass two parameters towards it: The first parameter <TT CLASS="parameter" ><I >$storageDriver</I ></TT > represents the type of storage container, the class shall use. In our example, the container is a database. The second parameter <TT CLASS="parameter" ><I > $storageOptions</I ></TT > defines some parameters that are passed to the storage container. When using the PEAR DB layer, this 2nd parameter has to be the DSN string that tells the DB layer how to connect. </P ><P > The function <B CLASS="function" >start()</B > checks, if the user is already logged in. If this check leads into a positive result, the function does nothing more. If <B CLASS="function" >start()</B > detects, that the user isn't already logged in, it starts the authentication mechanism: An HTML form is printed and the user can enter his login data. </P ><P > <B CLASS="function" >getAuth()</B > is a helper function that returns true if the user is logged and that returns false if he hasn't already logged in. </P ></DIV ></DIV ><?php manualFooter('','packages.auth.php'); ?> Index: pearweb/public_html/manual/packages.net_checkip.php +++ pearweb/public_html/manual/packages.net_checkip.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('packages.auth.php', ''), 'next' => array('index.php#AEN0', ''), 'up' => array('packages.php', 'PEAR Packages'), 'toc' => array( array('packages.php#packages', ''), array('packages.php#AEN0', ''), array('packages.skeleton.php', ''), array('packages.php#AEN0', ''), array('packages.auth.php', ''), array('packages.php#AEN0', ''), array('packages.net_checkip.php', '')))); manualHeader('','packages.net_checkip.php'); ?><DIV CLASS="ARTICLE" ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" ><A NAME="AEN454" >Net_CheckIP: Validation of IPv4 adresses</A ></H1 ><HR></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="packages.net_checkip.net_checkip" >Net_Checkip</A ></H1 ><P > This class can validate if a given string has a valid IPv4 syntax. </P ><P >Usage example:</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > require_once "Net_CheckIP/CheckIP.php"; if (Net_CheckIP::check_ip("your_ip_goes_here")) { // Syntax of the IP is ok } </PRE ></TD ></TR ></TABLE ><P > The function <B CLASS="function" >check_ip()</B > returns true, if the passed string has a valid IPv4 syntax. That means that it has to contain exactly 4 numbers between 0 and 255, which are all separated by a dot. </P ></DIV ></DIV ><?php manualFooter('','packages.net_checkip.php'); ?> Index: pearweb/public_html/manual/packages.php +++ pearweb/public_html/manual/packages.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('class.pear-error.php', 'PEAR_Error'), 'next' => array('packages.skeleton.php', ''), 'up' => array('index.php', 'PEAR Manual'), 'toc' => array( array('index.php#manual', ''), array('index.php#AEN0', ''), array('index.php#bookinfo', ''), array('index.php#AEN0', ''), array('preface.php', 'Preface'), array('getting-started.php', 'Getting Started'), array('packages.php', 'PEAR Packages')))); manualHeader('PEAR Packages','packages.php'); ?><DIV CLASS="PART" ><A NAME="packages" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >II. PEAR Packages</H1 ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="packages.skeleton.php" >Skeleton for creating PEAR docbook documentation</A ></DT ><DT ><A HREF="packages.auth.php" >Auth: creating authentication realms</A ></DT ><DT ><A HREF="packages.net_checkip.php" >Net_CheckIP: Validation of IPv4 adresses</A ></DT ></DL ></DIV ></DIV ></DIV ><?php manualFooter('PEAR Packages','packages.php'); ?> Index: pearweb/public_html/manual/packages.skeleton.php +++ pearweb/public_html/manual/packages.skeleton.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('packages.php', 'PEAR Packages'), 'next' => array('packages.auth.php', ''), 'up' => array('packages.php', 'PEAR Packages'), 'toc' => array( array('packages.php#packages', ''), array('packages.php#AEN0', ''), array('packages.skeleton.php', ''), array('packages.php#AEN0', ''), array('packages.auth.php', ''), array('packages.php#AEN0', ''), array('packages.net_checkip.php', '')))); manualHeader('','packages.skeleton.php'); ?><DIV CLASS="ARTICLE" ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" ><A NAME="AEN416" >Skeleton for creating PEAR docbook documentation</A ></H1 ><HR></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="packages.skeleton.classname" >Classname</A ></H1 ><P >This is a paragraph, where you can put text in.</P ><P ></P ><UL ><LI ><P >The first item in the itemized list</P ></LI ><LI ><P >An itemized list is comparable with >ul<>li<>/li<>/ul< in HTML </P ></LI ></UL ><P ><I CLASS="emphasis" >Emphase</I > something, could transform in cursive or bold in other formats like PDF or HTML </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > // Often, you have to add programing examples. // Everything between the CDATA-section is treaten "as is" // including tabs(!) go_ahead() ; </PRE ></TD ></TR ></TABLE ><P > <B CLASS="function" >This_is_a_functionname()</B > and <B CLASS="classname" >i_am_the_name_of_a_class</B > or do you want to describe a <TT CLASS="parameter" ><I >parameter</I ></TT >? </P ></DIV ></DIV ><?php manualFooter('','packages.skeleton.php'); ?> Index: pearweb/public_html/manual/preface.php +++ pearweb/public_html/manual/preface.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('index.php', 'PEAR Manual'), 'next' => array('getting-started.php', 'Getting Started'), 'up' => array('index.php', 'PEAR Manual'), 'toc' => array( array('index.php#manual', ''), array('index.php#AEN0', ''), array('index.php#bookinfo', ''), array('index.php#AEN0', ''), array('preface.php', 'Preface'), array('getting-started.php', 'Getting Started'), array('packages.php', 'PEAR Packages')))); manualHeader('Preface','preface.php'); ?><DIV CLASS="preface" ><H1 ><A NAME="preface" >Preface</A ></H1 ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="preface.php#about" >About this Manual</A ></DT ></DL ></DIV ><BLOCKQUOTE CLASS="ABSTRACT" ><DIV CLASS="abstract" ><A NAME="AEN21" ></A ><P ></P ><P > <SPAN CLASS="acronym" >PEAR</SPAN > is the PHP Extension and Application Repository. </P ><P ></P ></DIV ></BLOCKQUOTE ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="about" >About this Manual</A ></H1 ><P > This manual is written in <SPAN CLASS="acronym" >XML</SPAN > using the <A HREF="http://www.nwalsh.com/docbook/xml/" TARGET="_top" >DocBook XML DTD</A >, using <A HREF="http://www.jclark.com/dsssl/" TARGET="_top" ><SPAN CLASS="acronym" >DSSSL</SPAN ></A > (Document Style and Semantics Specification Language) for formatting. The tools used for formatting <SPAN CLASS="acronym" >HTML</SPAN > versions are <A HREF="http://www.jclark.com/jade/" TARGET="_top" >Jade</A >, written by <A HREF="http://www.jclark.com/bio.htm" TARGET="_top" >James Clark</A > and <A HREF="http://nwalsh.com/docbook/dsssl/" TARGET="_top" >The Modular DocBook Stylesheets</A > written by <A HREF="http://nwalsh.com/" TARGET="_top" >Norman Walsh</A >. </P ><P > It is based on the great work, the PHP documentation group has done in the past. </P ></DIV ></DIV ><?php manualFooter('Preface','preface.php'); ?> Index: pearweb/public_html/manual/reference.php +++ pearweb/public_html/manual/reference.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('standards.naming.php', 'Naming Conventions'), 'next' => array('class.pear.php', 'PEAR'), 'up' => array('getting-started.php', 'Getting Started'), 'toc' => array( array('getting-started.php#getting-started', ''), array('getting-started.php#AEN0', ''), array('introduction.php', 'Introduction'), array('getting-started.php#AEN0', ''), array('standards.php', 'Coding Standards'), array('getting-started.php#AEN0', ''), array('reference.php', 'PEAR')))); manualHeader('PEAR Reference Manual','reference.php'); ?><DIV CLASS="reference" ><A NAME="reference" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >I. PEAR Reference Manual</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN201" ></A ><P > This chapter contains reference documentation for PEAR components that are distributed with PHP. It is assumed that you are already familiar with objects and classes. </P ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="class.pear.php" >PEAR</A > — PEAR base class</DT ><DT ><A HREF="class.pear-error.php" >PEAR_Error</A > — PEAR error mechanism base class</DT ></DL ></DIV ></DIV ></DIV ><?php manualFooter('PEAR Reference Manual','reference.php'); ?> Index: pearweb/public_html/manual/standards.comments.php +++ pearweb/public_html/manual/standards.comments.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('standards.funcdef.php', 'Function Definitions'), 'next' => array('standards.including.php', 'Including Code'), 'up' => array('standards.php', 'Coding Standards'), 'toc' => array( array('standards.php#standards', ''), array('standards.php#AEN57', ''), array('standards.php#standards.indenting', 'Indenting'), array('standards.control.php', 'Control Structures'), array('standards.funcalls.php', 'Function Calls'), array('standards.funcdef.php', 'Function Definitions'), array('standards.comments.php', 'Comments'), array('standards.including.php', 'Including Code'), array('standards.tags.php', 'PHP Code Tags'), array('standards.header.php', 'Header Comment Blocks'), array('standards.cvs.php', 'Using CVS'), array('standards.exampleurls.php', 'Example URLs'), array('standards.naming.php', 'Naming Conventions')))); manualHeader('Comments','standards.comments.php'); ?><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="standards.comments" >Comments</A ></H1 ><P > Inline documentation for classes should follow the PHPDoc convention, similar to Javadoc. More information about PHPDoc can be found here: <A HREF="http://www.phpdoc.de/" TARGET="_top" >http://www.phpdoc.de/</A > </P ><P > Non-documentation comments are strongly encouraged. A general rule of thumb is that if you look at a section of code and think "Wow, I don't want to try and describe that", you need to comment it before you forget how it works. </P ><P > C style comments (/* */) and standard C++ comments (//) are both fine. Use of Perl/shell style comments (#) is discouraged. </P ></DIV ><?php manualFooter('Comments','standards.comments.php'); ?> Index: pearweb/public_html/manual/standards.control.php +++ pearweb/public_html/manual/standards.control.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('standards.php', 'Coding Standards'), 'next' => array('standards.funcalls.php', 'Function Calls'), 'up' => array('standards.php', 'Coding Standards'), 'toc' => array( array('standards.php#standards', ''), array('standards.php#AEN57', ''), array('standards.php#standards.indenting', 'Indenting'), array('standards.control.php', 'Control Structures'), array('standards.funcalls.php', 'Function Calls'), array('standards.funcdef.php', 'Function Definitions'), array('standards.comments.php', 'Comments'), array('standards.including.php', 'Including Code'), array('standards.tags.php', 'PHP Code Tags'), array('standards.header.php', 'Header Comment Blocks'), array('standards.cvs.php', 'Using CVS'), array('standards.exampleurls.php', 'Example URLs'), array('standards.naming.php', 'Naming Conventions')))); manualHeader('Control Structures','standards.control.php'); ?><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="standards.control" >Control Structures</A ></H1 ><P > These include if, for, while, switch, etc. Here is an example if statement, since it is the most complicated of them: <TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > if ((condition1) || (condition2)) { action1; } elseif ((condition3) && (condition4)) { action2; } else { defaultaction; } </PRE ></TD ></TR ></TABLE > </P ><P > Control statements should have one space between the control keyword and opening parenthesis, to distinguish them from function calls. </P ><P > You are strongly encouraged to always use curly braces even in situations where they are technically optional. Having them increases readability and decreases the likelihood of logic errors being introduced when new lines are added. </P ><P > For switch statements: <TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > switch (condition) { case 1: action1; break; case 2: action2; break; default: defaultaction; break; } </PRE ></TD ></TR ></TABLE > </P ></DIV ><?php manualFooter('Control Structures','standards.control.php'); ?> Index: pearweb/public_html/manual/standards.cvs.php +++ pearweb/public_html/manual/standards.cvs.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('standards.header.php', 'Header Comment Blocks'), 'next' => array('standards.exampleurls.php', 'Example URLs'), 'up' => array('standards.php', 'Coding Standards'), 'toc' => array( array('standards.php#standards', ''), array('standards.php#AEN57', ''), array('standards.php#standards.indenting', 'Indenting'), array('standards.control.php', 'Control Structures'), array('standards.funcalls.php', 'Function Calls'), array('standards.funcdef.php', 'Function Definitions'), array('standards.comments.php', 'Comments'), array('standards.including.php', 'Including Code'), array('standards.tags.php', 'PHP Code Tags'), array('standards.header.php', 'Header Comment Blocks'), array('standards.cvs.php', 'Using CVS'), array('standards.exampleurls.php', 'Example URLs'), array('standards.naming.php', 'Naming Conventions')))); manualHeader('Using CVS','standards.cvs.php'); ?><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="standards.cvs" >Using CVS</A ></H1 ><P > This section applies only to packages using CVS at cvs.php.net. </P ><P > Include the $Id: standards.cvs.php,v 1.1 2001/10/14 15:27:53 mj Exp $ CVS keyword in each file. As each file is edited, add this tag if it's not yet present (or replace existing forms such as "Last Modified:", etc.). </P ><P > The rest of this section assumes that you have basic knowledge about CVS tags and branches. </P ><P > CVS tags are used to label which revisions of the files in your package belong to a given release. Below is a list of the required and suggested CVS tags: <P ></P ><DIV CLASS="variablelist" ><DL ><DT >RELEASE_<TT CLASS="replaceable" ><I >n_n</I ></TT ></DT ><DD ><P > (required) Used for tagging a release. If you don't use it, there's no way to go back and retrieve your package from the CVS server in the state it was in at the time of the release. </P ></DD ><DT >QA_<TT CLASS="replaceable" ><I >n_n</I ></TT ></DT ><DD ><P > (branch, optional) If you feel you need to roll out a release candidate before releasing, it's a good idea to make a branch for it so you can isolate the release and apply only those critical fixes before the actual release. Meanwhile, normal development may continue on the main trunk. </P ></DD ><DT >MAINT_<TT CLASS="replaceable" ><I >n_n</I ></TT ></DT ><DD ><P > (branch, optional) If you need to make "micro-releases" (for example 1.2.1 and so on after 1.2), you can use a branch for that too, if your main trunk is very active and you want only minor changes between your micro-releases. </P ></DD ></DL ></DIV > Only the RELEASE tag is required, the rest are recommended for your convenience. </P ><P > Below is an example of how to tag the 1.2 release of the "Money_Fast" package: <DIV CLASS="informalexample" ><A NAME="AEN139" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="screen" ><TT CLASS="prompt" >$ </TT ><B CLASS="command" >cd pear/Money_Fast</B > <TT CLASS="prompt" >$ </TT ><B CLASS="command" >cvs tag RELEASE_1_2</B > <TT CLASS="computeroutput" >T Fast.php T README T package.xml </TT > </PRE ></TD ></TR ></TABLE ><P ></P ></DIV > By doing this you make it possible for the PEAR web site to take you through the rest of your release process. </P ><P > Here's an example of how to create a QA branch: <DIV CLASS="informalexample" ><A NAME="AEN147" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="screen" ><TT CLASS="prompt" >$ </TT ><B CLASS="command" >cvs tag QA_2_0_BP</B > ... <TT CLASS="prompt" >$ </TT ><B CLASS="command" >cvs rtag -b -r QA_2_0_BP QA_2_0</B > <TT CLASS="prompt" >$ </TT ><B CLASS="command" >cvs update -r QA_2_0</B > <TT CLASS="prompt" >$ </TT ><B CLASS="command" >cvs tag RELEASE_2_0RC1</B > ...and then the actual release, from the same branch: <TT CLASS="prompt" >$ </TT ><B CLASS="command" >cvs tag RELEASE_2_0</B > </PRE ></TD ></TR ></TABLE ><P ></P ></DIV > The "QA_2_0_BP" tag is a "branch point" tag, which is the start point of the tag. It's always a good idea to start a CVS branch from such branch points. MAINT branches may use the RELEASE tag as their branch point. </P ></DIV ><?php manualFooter('Using CVS','standards.cvs.php'); ?> Index: pearweb/public_html/manual/standards.exampleurls.php +++ pearweb/public_html/manual/standards.exampleurls.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('standards.cvs.php', 'Using CVS'), 'next' => array('standards.naming.php', 'Naming Conventions'), 'up' => array('standards.php', 'Coding Standards'), 'toc' => array( array('standards.php#standards', ''), array('standards.php#AEN57', ''), array('standards.php#standards.indenting', 'Indenting'), array('standards.control.php', 'Control Structures'), array('standards.funcalls.php', 'Function Calls'), array('standards.funcdef.php', 'Function Definitions'), array('standards.comments.php', 'Comments'), array('standards.including.php', 'Including Code'), array('standards.tags.php', 'PHP Code Tags'), array('standards.header.php', 'Header Comment Blocks'), array('standards.cvs.php', 'Using CVS'), array('standards.exampleurls.php', 'Example URLs'), array('standards.naming.php', 'Naming Conventions')))); manualHeader('Example URLs','standards.exampleurls.php'); ?><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="standards.exampleurls" >Example URLs</A ></H1 ><P > Use "example.com" for all example URLs, per RFC 2606. </P ></DIV ><?php manualFooter('Example URLs','standards.exampleurls.php'); ?> Index: pearweb/public_html/manual/standards.funcalls.php +++ pearweb/public_html/manual/standards.funcalls.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('standards.control.php', 'Control Structures'), 'next' => array('standards.funcdef.php', 'Function Definitions'), 'up' => array('standards.php', 'Coding Standards'), 'toc' => array( array('standards.php#standards', ''), array('standards.php#AEN57', ''), array('standards.php#standards.indenting', 'Indenting'), array('standards.control.php', 'Control Structures'), array('standards.funcalls.php', 'Function Calls'), array('standards.funcdef.php', 'Function Definitions'), array('standards.comments.php', 'Comments'), array('standards.including.php', 'Including Code'), array('standards.tags.php', 'PHP Code Tags'), array('standards.header.php', 'Header Comment Blocks'), array('standards.cvs.php', 'Using CVS'), array('standards.exampleurls.php', 'Example URLs'), array('standards.naming.php', 'Naming Conventions')))); manualHeader('Function Calls','standards.funcalls.php'); ?><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="standards.funcalls" >Function Calls</A ></H1 ><P > Functions should be called with no spaces between the function name, the opening parenthesis, and the first parameter; spaces between commas and each parameter, and no space between the last parameter, the closing parenthesis, and the semicolon. Here's an example: <TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > $var = foo($bar, $baz, $quux); </PRE ></TD ></TR ></TABLE > </P ><P > As displayed above, there should be one space on either side of an equals sign used to assign the return value of a function to a variable. In the case of a block of related assignments, more space may be inserted to promote readability: <TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > $short = foo($bar); $long_variable = foo($baz); </PRE ></TD ></TR ></TABLE > </P ></DIV ><?php manualFooter('Function Calls','standards.funcalls.php'); ?> Index: pearweb/public_html/manual/standards.funcdef.php +++ pearweb/public_html/manual/standards.funcdef.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('standards.funcalls.php', 'Function Calls'), 'next' => array('standards.comments.php', 'Comments'), 'up' => array('standards.php', 'Coding Standards'), 'toc' => array( array('standards.php#standards', ''), array('standards.php#AEN57', ''), array('standards.php#standards.indenting', 'Indenting'), array('standards.control.php', 'Control Structures'), array('standards.funcalls.php', 'Function Calls'), array('standards.funcdef.php', 'Function Definitions'), array('standards.comments.php', 'Comments'), array('standards.including.php', 'Including Code'), array('standards.tags.php', 'PHP Code Tags'), array('standards.header.php', 'Header Comment Blocks'), array('standards.cvs.php', 'Using CVS'), array('standards.exampleurls.php', 'Example URLs'), array('standards.naming.php', 'Naming Conventions')))); manualHeader('Function Definitions','standards.funcdef.php'); ?><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="standards.funcdef" >Function Definitions</A ></H1 ><P > Function declaractions follow the "one true brace" convention: <TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > function fooFunction($arg1, $arg2 = '') { if (condition) { statement; } return $val; } </PRE ></TD ></TR ></TABLE > </P ><P > Arguments with default values go at the end of the argument list. Always attempt to return a meaningful value from a function if one is appropriate. Here is a slightly longer example: <TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > function connect(&$dsn, $persistent = false) { if (is_array($dsn)) { $dsninfo = &$dsn; } else { $dsninfo = DB::parseDSN($dsn); } if (!$dsninfo || !$dsninfo['phptype']) { return $this->raiseError(); } return true; } </PRE ></TD ></TR ></TABLE > </P ></DIV ><?php manualFooter('Function Definitions','standards.funcdef.php'); ?> Index: pearweb/public_html/manual/standards.header.php +++ pearweb/public_html/manual/standards.header.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('standards.tags.php', 'PHP Code Tags'), 'next' => array('standards.cvs.php', 'Using CVS'), 'up' => array('standards.php', 'Coding Standards'), 'toc' => array( array('standards.php#standards', ''), array('standards.php#AEN57', ''), array('standards.php#standards.indenting', 'Indenting'), array('standards.control.php', 'Control Structures'), array('standards.funcalls.php', 'Function Calls'), array('standards.funcdef.php', 'Function Definitions'), array('standards.comments.php', 'Comments'), array('standards.including.php', 'Including Code'), array('standards.tags.php', 'PHP Code Tags'), array('standards.header.php', 'Header Comment Blocks'), array('standards.cvs.php', 'Using CVS'), array('standards.exampleurls.php', 'Example URLs'), array('standards.naming.php', 'Naming Conventions')))); manualHeader('Header Comment Blocks','standards.header.php'); ?><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="standards.header" >Header Comment Blocks</A ></H1 ><P > All source code files in the core PEAR distribution should contain the following comment block as the header: <TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4.0 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Original Author <author@example.com> | // | Your Name <you@example.com> | // +----------------------------------------------------------------------+ // // $Id: standards.header.php,v 1.1 2001/10/14 15:27:53 mj Exp $ </PRE ></TD ></TR ></TABLE > </P ><P > There's no hard rule to determine when a new code contributer should be added to the list of authors for a given source file. In general, their changes should fall into the "substantial" category (meaning somewhere around 10% to 20% of code changes). Exceptions could be made for rewriting functions or contributing new logic. </P ><P > Simple code reorganization or bug fixes would not justify the addition of a new individual to the list of authors. </P ><P > Files not in the core PEAR repository should have a similar block stating the copyright, the license, and the authors. All files should include the modeline comments to encourage consistency. </P ></DIV ><?php manualFooter('Header Comment Blocks','standards.header.php'); ?> Index: pearweb/public_html/manual/standards.including.php +++ pearweb/public_html/manual/standards.including.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('standards.comments.php', 'Comments'), 'next' => array('standards.tags.php', 'PHP Code Tags'), 'up' => array('standards.php', 'Coding Standards'), 'toc' => array( array('standards.php#standards', ''), array('standards.php#AEN57', ''), array('standards.php#standards.indenting', 'Indenting'), array('standards.control.php', 'Control Structures'), array('standards.funcalls.php', 'Function Calls'), array('standards.funcdef.php', 'Function Definitions'), array('standards.comments.php', 'Comments'), array('standards.including.php', 'Including Code'), array('standards.tags.php', 'PHP Code Tags'), array('standards.header.php', 'Header Comment Blocks'), array('standards.cvs.php', 'Using CVS'), array('standards.exampleurls.php', 'Example URLs'), array('standards.naming.php', 'Naming Conventions')))); manualHeader('Including Code','standards.including.php'); ?><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="standards.including" >Including Code</A ></H1 ><P > Anywhere you are unconditionally including a class file, use <B CLASS="function" >require_once()</B >. Anywhere you are conditionally including a class file (for example, factory methods), use <B CLASS="function" >include_once()</B >. Either of these will ensure that class files are included only once. They share the same file list, so you don't need to worry about mixing them - a file included with <B CLASS="function" >require_once()</B > will not be included again by <B CLASS="function" >include_once()</B >. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > <B CLASS="function" >include_once()</B > and <B CLASS="function" >require_once()</B > are statements, not functions. You don't <I CLASS="emphasis" >need</I > parentheses around the filename to be included. </P ></BLOCKQUOTE ></DIV > </P ></DIV ><?php manualFooter('Including Code','standards.including.php'); ?> Index: pearweb/public_html/manual/standards.naming.php +++ pearweb/public_html/manual/standards.naming.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('standards.exampleurls.php', 'Example URLs'), 'next' => array('reference.php', 'PEAR'), 'up' => array('standards.php', 'Coding Standards'), 'toc' => array( array('standards.php#standards', ''), array('standards.php#AEN57', ''), array('standards.php#standards.indenting', 'Indenting'), array('standards.control.php', 'Control Structures'), array('standards.funcalls.php', 'Function Calls'), array('standards.funcdef.php', 'Function Definitions'), array('standards.comments.php', 'Comments'), array('standards.including.php', 'Including Code'), array('standards.tags.php', 'PHP Code Tags'), array('standards.header.php', 'Header Comment Blocks'), array('standards.cvs.php', 'Using CVS'), array('standards.exampleurls.php', 'Example URLs'), array('standards.naming.php', 'Naming Conventions')))); manualHeader('Naming Conventions','standards.naming.php'); ?><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="standards.naming" >Naming Conventions</A ></H1 ><DIV CLASS="sect2" ><H2 CLASS="sect2" ><A NAME="AEN164" >Functions and Methods</A ></H2 ><P > Functions and methods should be named using the "studly caps" style (also referred to as "bumpy case" or "camel caps"). Functions should in addition have the package name as a prefix, to avoid name collisions between packages. The initial letter of the name (after the prefix) is lowercase, and each letter that starts a new "word" is capitalized. Some examples: <DIV CLASS="informaltable" ><A NAME="AEN167" ></A ><P ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><P >connect()</P ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><P >getData()</P ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><P >buildSomeWidget()</P ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><P >XML_RPC_serializeData()</P ></TD ></TR ></TBODY ></TABLE ><P ></P ></DIV > </P ><P > Private class members (meaning class members that are intented to be used only from within the same class in which they are declared; PHP does not yet support truly-enforceable private namespaces) are preceeded by a single underscore. For example: <DIV CLASS="informaltable" ><A NAME="AEN180" ></A ><P ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><P >_sort()</P ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><P >_initTree()</P ></TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" ><P >$this->_status</P ></TD ></TR ></TBODY ></TABLE ><P ></P ></DIV > </P ></DIV ><DIV CLASS="sect2" ><H2 CLASS="sect2" ><A NAME="AEN190" >Constants</A ></H2 ><P > Constants should always be all-uppercase, with underscores to seperate words. Prefix constant names with the uppercased name of the class/package they are used in. For example, the constants used by the <TT CLASS="literal" >DB::</TT > package all begin with "<TT CLASS="literal" >DB_</TT >". </P ></DIV ><DIV CLASS="sect2" ><H2 CLASS="sect2" ><A NAME="AEN195" >Global Variables</A ></H2 ><P > If your package needs to define global variables, their name should start with a single underscore followed by the package name and another underscore. For example, the PEAR package uses a global variable called $_PEAR_destructor_object_list. </P ></DIV ></DIV ><?php manualFooter('Naming Conventions','standards.naming.php'); ?> Index: pearweb/public_html/manual/standards.php +++ pearweb/public_html/manual/standards.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('introduction.php', 'Introduction'), 'next' => array('standards.control.php', 'Control Structures'), 'up' => array('getting-started.php', 'Getting Started'), 'toc' => array( array('getting-started.php#getting-started', ''), array('getting-started.php#AEN0', ''), array('introduction.php', 'Introduction'), array('getting-started.php#AEN0', ''), array('standards.php', 'Coding Standards'), array('getting-started.php#AEN0', ''), array('reference.php', 'PEAR')))); manualHeader('Coding Standards','standards.php'); ?><DIV CLASS="chapter" ><H1 ><A NAME="standards" >Chapter 2. Coding Standards</A ></H1 ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="standards.php#standards.indenting" >Indenting</A ></DT ><DT ><A HREF="standards.control.php" >Control Structures</A ></DT ><DT ><A HREF="standards.funcalls.php" >Function Calls</A ></DT ><DT ><A HREF="standards.funcdef.php" >Function Definitions</A ></DT ><DT ><A HREF="standards.comments.php" >Comments</A ></DT ><DT ><A HREF="standards.including.php" >Including Code</A ></DT ><DT ><A HREF="standards.tags.php" >PHP Code Tags</A ></DT ><DT ><A HREF="standards.header.php" >Header Comment Blocks</A ></DT ><DT ><A HREF="standards.cvs.php" >Using CVS</A ></DT ><DT ><A HREF="standards.exampleurls.php" >Example URLs</A ></DT ><DT ><A HREF="standards.naming.php" >Naming Conventions</A ></DT ></DL ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > The PEAR Coding Standards applies to code that is to become a part of PEAR, either distributed with PHP or available for download via PEAR's install tool. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="standards.indenting" >Indenting</A ></H1 ><P > Use an indent of 4 spaces, with no tabs. If you use Emacs to edit PEAR code, you should set indent-tabs-mode to nil. Here is an example mode hook that will set up Emacs according to these guidelines (you will need to ensure that it is called when you are editing PHP files): <TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > (defun php-mode-hook () (setq tab-width 4 c-basic-offset 4 c-hanging-comment-ender-p nil indent-tabs-mode (not (and (string-match "/\\(PEAR\\|pear\\)/" (buffer-file-name)) (string-match "\.php$" (buffer-file-name)))))) </PRE ></TD ></TR ></TABLE > </P ><P >Here are vim rules for the same thing: <TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > set expandtab set shiftwidth=4 set tabstop=4 </PRE ></TD ></TR ></TABLE > </P ></DIV ></DIV ><?php manualFooter('Coding Standards','standards.php'); ?> Index: pearweb/public_html/manual/standards.tags.php +++ pearweb/public_html/manual/standards.tags.php <?php sendManualHeaders('ISO-8859-1','en'); setupNavigation(array( 'home' => array('index.php', 'PEAR Manual'), 'prev' => array('standards.including.php', 'Including Code'), 'next' => array('standards.header.php', 'Header Comment Blocks'), 'up' => array('standards.php', 'Coding Standards'), 'toc' => array( array('standards.php#standards', ''), array('standards.php#AEN57', ''), array('standards.php#standards.indenting', 'Indenting'), array('standards.control.php', 'Control Structures'), array('standards.funcalls.php', 'Function Calls'), array('standards.funcdef.php', 'Function Definitions'), array('standards.comments.php', 'Comments'), array('standards.including.php', 'Including Code'), array('standards.tags.php', 'PHP Code Tags'), array('standards.header.php', 'Header Comment Blocks'), array('standards.cvs.php', 'Using CVS'), array('standards.exampleurls.php', 'Example URLs'), array('standards.naming.php', 'Naming Conventions')))); manualHeader('PHP Code Tags','standards.tags.php'); ?><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="standards.tags" >PHP Code Tags</A ></H1 ><P > <I CLASS="emphasis" >Always</I > use <TT CLASS="literal" ><?php ?></TT > to delimit PHP code, not the <TT CLASS="literal" ><? ?></TT > shorthand. This is required for PEAR compliance and is also the most portable way to include PHP code on differing operating systems and setups. </P ></DIV ><?php manualFooter('PHP Code Tags','standards.tags.php'); ?>