1

Is there a way to find errors caused by crafted input in php, such as naming POST-fields like variable[] instead of variable, causing PHP to implicitly convert it into an array, by using some form of automated testing?

asked May 3, 2014 at 22:30
1
  • Could you detail the kind of testing you have in mind? Ideally whatever code consumes the POST data would have its own validation logic. Commented May 4, 2014 at 8:43

1 Answer 1

1

Use type assertions as annotations in the code:

class Author
{
 /**
 * @Assert\Type("string")
 */
 protected $firstName;
 /**
 * @Assert\Type(
 * type="integer",
 * message="The value {{ value }} is not a valid {{ type }}."
 * )
 */
 protected $age;
}

Or settype in the tests themselves:

$foo = "42";
echo gettype($foo); // Yields "string"
// Here we change the type from string -> integer
settype($foo, "integer");
echo gettype($foo); // Yields "integer"

References

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.