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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil Powell

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

    <?
    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('~' , '&#126;',
    $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('~' , '&#126;',
    $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('~' , '&#126;',
    $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('~' , '&#126;',
    $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('~' , '&#126;',
    $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
  • Jochen Daum

    #2
    Re: clearer post to method/property/class problem - help appreciated

    Hi Phil!

    (...)[color=blue]
    >
    > 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?[/color]

    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.
    Download PHP DB Edit Toolkit for free. PHP DB Edit Toolkit is a set of PHP classes makes the generation of database edit interfaces easier and faster. The main class builds tabular and form views based on a data dictionary and takes over handling of insert/update/delete and user input.

    Comment

    Working...