From 51e297e4e1f22dd720eccf41837eea4c6db323a0 Mon Sep 17 00:00:00 2001 From: Stig Bakken Date: Wed, 7 Mar 2001 20:35:26 +0000 Subject: [PATCH] * started documenting the PEAR base class and error mechanism git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@42900 c90b9560-bf6c-de11-be94-00142212c4b1 --- pear/pear.xml | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 pear/pear.xml diff --git a/pear/pear.xml b/pear/pear.xml new file mode 100644 index 0000000000..dca79a87a1 --- /dev/null +++ b/pear/pear.xml @@ -0,0 +1,126 @@ + + PEAR: the PHP Extension and Application Repository + PEAR + + + PEAR + PEAR base class + + + Description + + 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. + + + Its key features are: + + + request-shutdown object "destructors" + + + error handling + + + + + + Examples + + 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: + + PEAR: emulated destructors + +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. + + + + + + PEAR "destructors" use PHP's shutdown callbacks + (register_shutdown_function), 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. + + + + + + + + PEAR_Error + PEAR error mechanism base class + + + Description + + + + +