Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Error Handling Example From PEAR Manual
Howdy,

I'm brand new to playing with PEAR, and I'm not sure if this is the
correct list to post this to, but I think there is an error in example
13-1 of the PEAR manual concerning "emulated destructors":

Code from the manual (with added line and comments in red):


require_once "PEAR.php";

class FileContainer extends PEAR
{
var $file = '';
var $contents = '';
var $modified = 0;

function FileContainer($file)// $file contains the string, "testfile" from t
he instantiation below
{                                                                      //
but has not yet been assigned to the member attribute, $file...
$this->file = $file; // otherwise fopen call in
destructor returns false...
$this->PEAR(); // this calls the parent class constructor
$fp = fopen($file, "r");
if (!is_resource($fp)) {
return;
}
while ($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"); // otherwise, $this->file is empty...
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.



Hope this can be passed along to the right folks. Since I've just
installed PEAR, and the above was my test case for whether it was working
correctly, it took some time to realize that it wasn't my setup but the
example code that was broken.

dave

Report this thread to moderator Post Follow-up to this message
Old Post
dpgirago@mdanderson.org
08-27-04 08:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Pear archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:56 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.