I am thinking about building a modular validation class where different files are included depending on the data being checked.
While getting ready to start building this I came across some stuff that works but I don't understand why.
Why does this allow me to "require" the same file multiple times without throwing an error?
How does the server load, execute, and ???unload??? files in function MMVtest()?
Does it load it all and then execute or load during execution and unload when it is done with MMVtest()? I really don't understand the scope of classes in this case.
Here are the test files all in one directory:
Test.php ( The main file that will have data I want to check - Open This page to execute the code.)
<?php
include ('Mod.php');
$MyText = new MMVobj();
$MyText2 = new MMVobj();
$MyText3 = new MMVobj();
echo "<p>".$MyText->MESS."-".$MyText->ERROR."</p>";
echo "<p>".$MyText2->MESS."-".$MyText2->ERROR."</p>";
echo "<p>".$MyText3->MESS."-".$MyText3->ERROR."</p><hr/>";
echo "<p>MyText1- Calling Test 'simple'</p>";
echo "<p>MyText2- Calling Test 'simple2'</p>";
$MyText->MMVtest('simple',"MyText");
$MyText2->MMVtest('simple2',"MyText2");
echo "<p>".$MyText->MESS."-".$MyText->ERROR."</p>";
echo "<p>".$MyText2->MESS."-".$MyText2->ERROR."</p>";
echo "<p>".$MyText3->MESS."-".$MyText3->ERROR."</p><hr/>";
echo "<p>MyText1- Calling Test 'simple'</p>";
echo "<p>MyText2- Calling Test 'simple2'</p>";
echo "<p>MyText3- Calling Test 'simple3'</p>";
$MyText->MMVtest('simple',"MyText");
$MyText2->MMVtest('simple2',"MyText2");
$MyText3->MMVtest('simple3',"MyText3");
echo "<p>".$MyText->MESS."-".$MyText->ERROR."</p>";
echo "<p>".$MyText2->MESS."-".$MyText2->ERROR."</p>";
echo "<p>".$MyText3->MESS."-".$MyText3->ERROR."</p><hr/>";
echo "<p>MyText1- Calling Test 'simple2'</p>";
echo "<p>MyText2- Calling Test 'simple3'</p>";
$MyText->MMVtest('simple2',"MyText");
$MyText2->MMVtest('simple3',"MyText2");
echo "<p>".$MyText->MESS."-".$MyText->ERROR."</p>";
echo "<p>".$MyText2->MESS."-".$MyText2->ERROR."</p>";
echo "<p>".$MyText3->MESS."-".$MyText3->ERROR."</p><hr/>";
?>
Mod.php ( The Main Class File that constructs the validators)
<?php
class MMVobj
{
var $ERROR = ""; // Short Error Description
var $MESS = ""; // Message to present to user
function MMVobj ()
{
return;
}
function MMVtest ($TestType, $data)
{
require $TestType.'.php';
}
}
?>
3 Files all the same simple.php, simple2.php, simple3.php
(This will be all different later to do different checks)
<?php
$this->MESS = $data;
$this->ERROR = $TestType;
?>
Thanks all....:queasy: ๐