My first larger project is growing out of control. I've spent some weeks reading OOP tutorials, and feel ready to make my first dive into a new programming style. One of the things that led me this way was the need for user configuration of my project. Therefor, I'll start with a class that let's me read and write a configuration file.
Is this a good start, or should I change anything?
class configuration
{
var $configurationFile; function configuration($configurationFile)
{
$this->setConfigurationFile($configurationFile);
} function setConfigurationFile($configurationFile)
{
// Code to check that $configurationFile points to a valid file
} function readConfigurationFile()
{
$configurationArray = parse_ini_file($this->configurationFile, TRUE);
return $configurationArray;
} function writeConfigurationFile($changedValues)
{
$fp = fopen($this->configurationFile, "r" );
$contents = fread($fp, filesize($this->configurationFile));
fclose($fp);foreach ($changedValues as $changedValue)
{
$new_contents = ereg_replace($changedValue[old], $changedValue[new], $contents);
$contents = $new_contents;
}
$fp = fopen($this->configurationFile, "w" );
fwrite($fp, $contents);
fclose($fp);
}
}Best regards,
-- anders thoresson
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

