WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some values to save into postmeta and usermeta table. Before save, I already done this: $value = intval($value) . I think this is enough. But I see some plugins still use filters on those numbers. I want to make sure that I can do with intval and without safety filter.

share|improve this question
up vote 1 down vote accepted

intval() behaves sometimes a little bit counter-intuitive when then value has leading zeros or when it is a mathematic expression. The result should always be safe, but is not always what you might expect.

A simple example:

intval( '9223372036854775808' );

will never return this value, because even 64 bit system cannot handle such a large number. You get 9223372036854775807 on a 64 bit system and 2147483647 on 32 bit.

But if you use:

preg_match( '~\d+~', '9223372036854775808', $matches );

$matches[0] will return this number unchanged.

So, it depends on the values you expect.

share|improve this answer
I see. I will only use it on tiny numbers, 1, -1, and 0. so, that should be fine. Anyway, it's interesting to learn this behavior. – Jenny Sep 22 '12 at 10:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.