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

This is a discussion on clearer post to method/property/class problem - help appreciated within the PHP Language forums, part of the PHP Programming Forums category; <? class ErrorMsgCollection { var $name; var $mandatory; var $emptyErr; var $maxLength; var $maxLengthErr; var $minLength; var $minLenghtErr; var $pattern; var $...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-27-2003
Phil Powell
 
Posts: n/a
Default clearer post to method/property/class problem - help appreciated

<?
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
Reply With Quote
  #2 (permalink)  
Old 10-28-2003
Jochen Daum
 
Posts: n/a
Default Re: clearer post to method/property/class problem - help appreciated

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/
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:40 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0