<?
class ErrorMsgCollect ion {
var $name;
var $mandatory;
var $emptyErr;
var $maxLength;
var $maxLengthErr;
var $minLength;
var $minLenghtErr;
var $pattern;
var $patternErr;
var $arrayMandatory AmountType;
var $validArrayErr;
var $isAssoc;
var $erroredArrayAs socIndexArray;
function ErrorMsgCollect ion() {
$this->name = '';
$this->arrayMandatory AmountType = ''; // DEFAULT TO NULL
$this->validArrayEr r = $emptyErr; // DEFAULT TO SAME ERROR MSG AS
EMPTY ERR MSG
$this->assocIndex = 0; // DEFAULT TO 0 WILL BE USED AS INDEX KEY FOR
CONVERTING ERR ARRAY (IF INDICATED) TO ASSOCIATIVE
$this->erroredArrayAs socIndexArray = array();
return true;
}
function getErroredArray AssocIndex($key ) {
return $this->erroredArrayAs socIndexArray[$key];
}
function getEmptyErr() {
if ($this->getIsAssoc() ) return $this->emptyErr . '~IsAssoc~' .
str_replace('~' , '~',
$this->getErroredArra yAssocIndex($th is->name));
return $this->emptyErr;
}
function getIsAssoc() {
return $this->isAssoc;
}
function getMandatory() {
return $this->mandatory;
}
function getMaxLength() {
return $this->maxLength;
}
function getMaxLengthErr () {
if ($this->getIsAssoc() ) return $this->emptyErr . '~IsAssoc~' .
str_replace('~' , '~',
$this->getErroredArra yAssocIndex($th is->name));
return $this->maxLengthErr ;
}
function getMinLength() {
return $this->minLength;
}
function getMinLengthErr () {
if ($this->getIsAssoc() ) return $this->emptyErr . '~IsAssoc~' .
str_replace('~' , '~',
$this->getErroredArra yAssocIndex($th is->name));
return $this->minLengthErr ;
}
function getName() {
return $this->name;
}
function getPattern() {
return $this->pattern;
}
function getPatternErr() {
if ($this->getIsAssoc() ) return $this->emptyErr . '~IsAssoc~' .
str_replace('~' , '~',
$this->getErroredArra yAssocIndex($th is->name));
return $this->patternErr;
}
function getValidArray() {
return $this->arrayMandatory AmountType;
}
function getValidArrayEr r() {
if ($this->getIsAssoc() ) return $this->emptyErr . '~IsAssoc~' .
str_replace('~' , '~',
$this->getErroredArra yAssocIndex($th is->name));
return $this->validArrayEr r;
}
function setErroredArray AssocIndex($arr ayName, $assocIndex) {
$this->erroredArrayAs socIndexArray =
$this->erroredArrayAs socIndexArray + array($arrayNam e => $assocIndex);
}
function setIsAssoc($isA ssoc) {
$this->isAssoc = $isAssoc;
}
function setMandatory($m andatory,$empty Err) {
$this->mandatory = $mandatory;
$this->emptyErr = $emptyErr;
}
function setMaxLength($m axLength,$maxLe ngthErr) {
$this->maxLength = $maxLength;
$this->maxLengthErr = $maxLengthErr;
}
function setMinLength($m inLength,$minLe ngthErr) {
$this->minLength = $minLength;
$this->minLengthErr = $minLengthErr;
}
function setName($name) {
$this->name = $name;
}
function setPattern($pat tern,$patternEr r) {
$this->pattern = $pattern;
$this->patternErr = $patternErr;
}
function setValidArray($ arrayMandatoryA mountType,$vali dArrayErr) {
$this->arrayMandatory AmountType = $arrayMandatory AmountType;
$this->validArrayEr r = $validArrayErr;
}
}
class FormValidator {
// $errormsgObjArr ay WILL BE AN ARRAY OF ErrorMsgCollect ion OBJECTS
var $validator, $errors, $isValid;
var $post, $errorMsgObjArr ay, $dateFormFields Array;
function FormValidator($ post, $errorMsgObjArr ay, $dateFormFields Array
= array()) {
$this->validator = null;
$this->errors = array();
$this->isValid = true;
$this->post = $post;
$this->errorMsgObjArr ay =& $errorMsgObjArr ay;
$this->dateFormFields Array = $dateFormFields Array;
}
function getErrorArray() {
return $this->errors;
}
function isValid() {
foreach ($this->errorMsgObjArr ay as $key => $val) {
print_r(get_cla ss_methods($val )); print_r("<P>");
print_r($val->name . "<P>");
print_r($val->getName() . "<P>");
}
return $this->isValid;
}
}
?>
The first print_r works, it produces an array of methods including
"getName".
The second print_r works, it produces the value of $val->name being
"Whatever" or something.
The third print_r fails, and here is the error:
Fatal error: Call to a member function on a non-object in
/var/www/html/development/phillip/libdev/formvalidation. inc on line
150
I am totally baffled as to this behavior because it makes absolutely
no sense to me, no matter what I have read about classes, this makes
no sense at all. How can a class object suddenly NOT become an object
by the next line?
Phil
class ErrorMsgCollect ion {
var $name;
var $mandatory;
var $emptyErr;
var $maxLength;
var $maxLengthErr;
var $minLength;
var $minLenghtErr;
var $pattern;
var $patternErr;
var $arrayMandatory AmountType;
var $validArrayErr;
var $isAssoc;
var $erroredArrayAs socIndexArray;
function ErrorMsgCollect ion() {
$this->name = '';
$this->arrayMandatory AmountType = ''; // DEFAULT TO NULL
$this->validArrayEr r = $emptyErr; // DEFAULT TO SAME ERROR MSG AS
EMPTY ERR MSG
$this->assocIndex = 0; // DEFAULT TO 0 WILL BE USED AS INDEX KEY FOR
CONVERTING ERR ARRAY (IF INDICATED) TO ASSOCIATIVE
$this->erroredArrayAs socIndexArray = array();
return true;
}
function getErroredArray AssocIndex($key ) {
return $this->erroredArrayAs socIndexArray[$key];
}
function getEmptyErr() {
if ($this->getIsAssoc() ) return $this->emptyErr . '~IsAssoc~' .
str_replace('~' , '~',
$this->getErroredArra yAssocIndex($th is->name));
return $this->emptyErr;
}
function getIsAssoc() {
return $this->isAssoc;
}
function getMandatory() {
return $this->mandatory;
}
function getMaxLength() {
return $this->maxLength;
}
function getMaxLengthErr () {
if ($this->getIsAssoc() ) return $this->emptyErr . '~IsAssoc~' .
str_replace('~' , '~',
$this->getErroredArra yAssocIndex($th is->name));
return $this->maxLengthErr ;
}
function getMinLength() {
return $this->minLength;
}
function getMinLengthErr () {
if ($this->getIsAssoc() ) return $this->emptyErr . '~IsAssoc~' .
str_replace('~' , '~',
$this->getErroredArra yAssocIndex($th is->name));
return $this->minLengthErr ;
}
function getName() {
return $this->name;
}
function getPattern() {
return $this->pattern;
}
function getPatternErr() {
if ($this->getIsAssoc() ) return $this->emptyErr . '~IsAssoc~' .
str_replace('~' , '~',
$this->getErroredArra yAssocIndex($th is->name));
return $this->patternErr;
}
function getValidArray() {
return $this->arrayMandatory AmountType;
}
function getValidArrayEr r() {
if ($this->getIsAssoc() ) return $this->emptyErr . '~IsAssoc~' .
str_replace('~' , '~',
$this->getErroredArra yAssocIndex($th is->name));
return $this->validArrayEr r;
}
function setErroredArray AssocIndex($arr ayName, $assocIndex) {
$this->erroredArrayAs socIndexArray =
$this->erroredArrayAs socIndexArray + array($arrayNam e => $assocIndex);
}
function setIsAssoc($isA ssoc) {
$this->isAssoc = $isAssoc;
}
function setMandatory($m andatory,$empty Err) {
$this->mandatory = $mandatory;
$this->emptyErr = $emptyErr;
}
function setMaxLength($m axLength,$maxLe ngthErr) {
$this->maxLength = $maxLength;
$this->maxLengthErr = $maxLengthErr;
}
function setMinLength($m inLength,$minLe ngthErr) {
$this->minLength = $minLength;
$this->minLengthErr = $minLengthErr;
}
function setName($name) {
$this->name = $name;
}
function setPattern($pat tern,$patternEr r) {
$this->pattern = $pattern;
$this->patternErr = $patternErr;
}
function setValidArray($ arrayMandatoryA mountType,$vali dArrayErr) {
$this->arrayMandatory AmountType = $arrayMandatory AmountType;
$this->validArrayEr r = $validArrayErr;
}
}
class FormValidator {
// $errormsgObjArr ay WILL BE AN ARRAY OF ErrorMsgCollect ion OBJECTS
var $validator, $errors, $isValid;
var $post, $errorMsgObjArr ay, $dateFormFields Array;
function FormValidator($ post, $errorMsgObjArr ay, $dateFormFields Array
= array()) {
$this->validator = null;
$this->errors = array();
$this->isValid = true;
$this->post = $post;
$this->errorMsgObjArr ay =& $errorMsgObjArr ay;
$this->dateFormFields Array = $dateFormFields Array;
}
function getErrorArray() {
return $this->errors;
}
function isValid() {
foreach ($this->errorMsgObjArr ay as $key => $val) {
print_r(get_cla ss_methods($val )); print_r("<P>");
print_r($val->name . "<P>");
print_r($val->getName() . "<P>");
}
return $this->isValid;
}
}
?>
The first print_r works, it produces an array of methods including
"getName".
The second print_r works, it produces the value of $val->name being
"Whatever" or something.
The third print_r fails, and here is the error:
Fatal error: Call to a member function on a non-object in
/var/www/html/development/phillip/libdev/formvalidation. inc on line
150
I am totally baffled as to this behavior because it makes absolutely
no sense to me, no matter what I have read about classes, this makes
no sense at all. How can a class object suddenly NOT become an object
by the next line?
Phil
Comment