By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,314 Members | 1,758 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,314 IT Pros & Developers. It's quick & easy.

clearer post to method/property/class problem - help appreciated

P: n/a
<?
class ErrorMsgCollection {

var $name;
var $mandatory;
var $emptyErr;
var $maxLength;
var $maxLengthErr;
var $minLength;
var $minLenghtErr;
var $pattern;
var $patternErr;
var $arrayMandatoryAmountType;
var $validArrayErr;
var $isAssoc;
var $erroredArrayAssocIndexArray;

function ErrorMsgCollection() {
$this->name = '';
$this->arrayMandatoryAmountType = ''; // DEFAULT TO NULL
$this->validArrayErr = $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->erroredArrayAssocIndexArray = array();
return true;
}

function getErroredArrayAssocIndex($key) {
return $this->erroredArrayAssocIndexArray[$key];
}
function getEmptyErr() {
if ($this->getIsAssoc()) return $this->emptyErr . '~IsAssoc~' .
str_replace('~', '~',
$this->getErroredArrayAssocIndex($this->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->getErroredArrayAssocIndex($this->name));
return $this->maxLengthErr;
}

function getMinLength() {
return $this->minLength;
}

function getMinLengthErr() {
if ($this->getIsAssoc()) return $this->emptyErr . '~IsAssoc~' .
str_replace('~', '~',
$this->getErroredArrayAssocIndex($this->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->getErroredArrayAssocIndex($this->name));
return $this->patternErr;
}

function getValidArray() {
return $this->arrayMandatoryAmountType;
}

function getValidArrayErr() {
if ($this->getIsAssoc()) return $this->emptyErr . '~IsAssoc~' .
str_replace('~', '~',
$this->getErroredArrayAssocIndex($this->name));
return $this->validArrayErr;
}

function setErroredArrayAssocIndex($arrayName, $assocIndex) {
$this->erroredArrayAssocIndexArray =
$this->erroredArrayAssocIndexArray + array($arrayName => $assocIndex);
}

function setIsAssoc($isAssoc) {
$this->isAssoc = $isAssoc;
}
function setMandatory($mandatory,$emptyErr) {
$this->mandatory = $mandatory;
$this->emptyErr = $emptyErr;
}

function setMaxLength($maxLength,$maxLengthErr) {
$this->maxLength = $maxLength;
$this->maxLengthErr = $maxLengthErr;
}

function setMinLength($minLength,$minLengthErr) {
$this->minLength = $minLength;
$this->minLengthErr = $minLengthErr;
}

function setName($name) {
$this->name = $name;
}

function setPattern($pattern,$patternErr) {
$this->pattern = $pattern;
$this->patternErr = $patternErr;
}

function setValidArray($arrayMandatoryAmountType,$validArra yErr) {
$this->arrayMandatoryAmountType = $arrayMandatoryAmountType;
$this->validArrayErr = $validArrayErr;
}
}

class FormValidator {

// $errormsgObjArray WILL BE AN ARRAY OF ErrorMsgCollection OBJECTS

var $validator, $errors, $isValid;
var $post, $errorMsgObjArray, $dateFormFieldsArray;

function FormValidator($post, $errorMsgObjArray, $dateFormFieldsArray
= array()) {
$this->validator = null;
$this->errors = array();
$this->isValid = true;
$this->post = $post;
$this->errorMsgObjArray =& $errorMsgObjArray;
$this->dateFormFieldsArray = $dateFormFieldsArray;
}

function getErrorArray() {
return $this->errors;
}

function isValid() {
foreach ($this->errorMsgObjArray as $key => $val) {
print_r(get_class_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
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi Phil!

(...)

function isValid() {
foreach ($this->errorMsgObjArray as $key => $val) {
print_r(get_class_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?


It doesn't have to be an object in the second line. If it is not
defined at this point, PHP will create one with name as a property.

Try

error-reporting(E_ALL);, this may give you an undefined property on
the second one.

And print_r ($val);
HTH ,jochen
--
Jochen Daum - CANS Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.