Re: disappearing array?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 20 Sep 2007 12:58:28 -0600, you wrote:

>I am not sure what the heck is going with this but here is my problem.
>
>I am trying to validate the contents of an array, then determine if the
>errors are with the array or another form submitted variable.
>
>The problem is after the code validates the array and other form
>variables using an if statement, I then try to determine if the error is
>in the array but for some reason the contents of the array disappear.
>
>Weird. Any help is appreciated.

Very hard to suggest anything from the snippet presented, as it can't
be run without the supporting classes (ValidateStrings and whatever
$fix is supposed to be), and it won't parse; the // comment on the end
of line 9 borks it, and the if () on line 21 is missing its closing
brace.

If I assume one run-on if() statement and add the closing brace, I'd
say that this looks weird:

if( $fix->ValArray( $_POST['add_order_items'] === -1 ) )
{
    $errors['add_order_array'] = $erlink;
}

In your snippet ValArray() appears to be a function, rather than a
method of $fix.

I suggest adding

error_reporting(E_ALL);

to the top of the script and letting us know what the output is, then
try to put together a minimal example that can actually be run (even
if you have to fake a ValidateStrings class that always returns -1)
and still shows your error.

Plus some general suggestions, feel free to ignore...

I think you're using || where you mean to use && in that run-on if()
statement. You're saying

IF (NOT Integer OR NOT Paragraph OR NOT Money)

which will always evaluate to true.

Unless your ValidateStrings class is holding some kind of state data
internally, it may be a good candidate for a static class.

ValidateStrings::ValidateParagraph()

is a bit verbose, how about just

Validate::Integer()
Validate::Paragraph()

etc.

In PHP, it's more typical to use true/false for success failure,
rather than returning -1 on failure, something like:

if (!Validate::Integer($value) && !Validate::Paragraph($value))
{
    /* failure */
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux