473,385 Members | 1,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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
Jul 17 '05 #1
1 1858
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Michael Brennan-White | last post by:
If I submit my for using a get action the resulting page loads . If I use a post action I get an error page saying "The page cannot be found". I am calling the originating page!!! This happens...
7
by: Edward Diener | last post by:
This simple code example gives me the message, "TypeError: 'staticmethod' object is not callable". class X(object): def Y(x): print x Y = staticmethod(Y) ad = { 1 : Y } def Z(self):...
0
by: Lucas, Todd | last post by:
Hello everyone! I'm having a problem with a WebControl that I'm designing for a Menu. I've been at it for about 3 weeks now, and can't seem to get around this problem. So I'm hoping that someone...
8
by: Gert | last post by:
Hi, I have a form (server side) because of the filling of variables through the application. But now I need to post it to an url on submit. My .HTML form looks like this, but how to translate it...
3
by: Amin Sobati | last post by:
Hi, I have two classes. Class2 inhertis Class1: ----------------------------- Public Class Class1 Public Overridable Sub MySub() End Sub End Class Public Class Class2
3
by: Patrick Fogarty | last post by:
I am programming what is to be a web service client that will use an HTTP-POST to request and retrieve data. The remote server (written in java for what it's worth) requires basic authentication...
4
by: ms | last post by:
Something weird is going on here, an HttpHandler works perfectly, exect when I post a form to it using the post method it gives me an file not found 404 error, if I post to it using the get method...
2
by: CindyH | last post by:
Hi Trying to get this code to work for http xml post. I need the post to be xml (doc.outerxml) sent in single key name as stream. The following is the post code and code for receiving the request....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.