views:

24

answers:

1

I don't know enough about when and how various variables are returned. Considering I have an conditional statement with an object to validate inside of this. Am I right that this is returned as a boolean value.

if($id = $oE->validate($_POST, $_FILES)){
...
}

What I really want is for this to return an array of errors if there are any errors, otherwise it will return the $id of the updated content.

With this above, it seems to return a boolean true if any value at all is returned by the validate() object??

+1  A: 

PHP interprets any non-zero value as true. What you need is to pass a reference which holds any error codes, and get the function to either return false on failure or the id on success. ie:

class Validator()
    {
    function validate($post,$files,$errorRef)
        {
        //Your code here
        if ($success)
            {
            return $id;
            }
        else
            {
            $errorRef = $errorCode;
            return false;
            }
        }
    }
//
$oE = new Validator;
$error = NULL;
$id = $oE->validate($_POST,$_FILES,&$error);
if ($id !== false) //If validator did not return false
    {
    //Stuff happens
    }
else
    {
    switch ($error)
        {
        //Error Handling Stuff
        }
    }
Andrew Dunn
yea thats what I figured, but what if I also need the $errors produced on failure, rather than just false. I suppose I could store it elsewhere...
kalpaitch
Andrew Dunn
ah yes yes i see, thank you
kalpaitch