note 54124 added to language.oop5.autoload
| From: | christopher dot klein at ecw dot de | Date: | Fri, 24 Jun 2005 11:49:51 +0000 |
| Subject: | note 54124 added to language.oop5.autoload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-90888@lists.php.net to get a copy of this message | ||
I'am currently developing an application with Propel.
I still don't designed all objects with their specific properties.
But I have already a rudementary framework,
which makes use of the Propel-Methods (getter and setter).
Imagine, you have a class Example_ManagementFileObject.
The class handles operations in conjunction with a FileObject.
The FileObject ist still not designed - because of different reasons.
This Example_ManagementFileObject looks like this:
class Example_ManagementFileObject
{
public static $objFile;
public static function writeDataToFile($nameOfFile, $stringToWrite)
{
self::$objFile = new FileObject()
self::$objFile->setNameOfFile($nameOfFile);
self::$objFile->setString($stringToWrite);
self::$objFile->setSave(1);
}
pulbic static function getSavedString()
{
if (is_object(self::$objFile))
{
return self::$objFile->getString();
}
return false;
}
}
----
Now we use a method, which I want to call "Extreme Prototyping".
We test our Example_ManagementFileObject::writeDataToFile()-Method:
----
/**
* __autoload($className)
* Searches all defined search-pathes.
* if the new object does not exists, it will be created
*/
function __autoload($className)
{
$arrPath = array('../classes/'');
for ($i = 0, $m = sizeof($arrSearchPath); $i < $m; $i++)
{
if (file_exists($arrPath[$i].$className.".php5"))
{
include_once($arrPath[$i].$className.".php5");
return true;
}
}
$str = 'class '.$className.'
{
private static $objInstances = array();
public function __construct()
{
self::$objInstances[] = $this;
}
private $objVals = array(); public static $test = "TEST";
public function __call($m, $a)
{
if (preg_match("/^(set|get)(.*)/",$m,$arrRet))
{
if ($arrRet[1] == "get")
{
if ($this->objVals[$arrRet[2]])
{
return $this->objVals[$arrRet[2]];
}
}
else
{
$this->objVals[$arrRet[2]] = $a[0];
return true;
}
}
}
public function dumpVar()
{
var_dump($this);
}
public static function dumpObjects()
{
var_dump(self::$objInstances);
print "</pre>";
}
}';
eval($str);
}
$myString = "Extreme Prototyping";
Example_ManagementFileObject::writeDataToFile($testFile, $myString);
if (Example_ManagementFileObject::getSavedString() == $myString)
{
print "Extreme Prototyping was successful.";
}
----
I Hope, you could use it =;)
Best regards,
Christopher Klein
----
Manual Page -- http://www.php.net/manual/en/language.oop5.autoload.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54124
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54124&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54124&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54124&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54124&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54124&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54124&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54124&report=yes
Search -- http://master.php.net/manage/user-notes.php